2011-09-23 12:00:45 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
2012-02-29 16:07:11 +03:00
|
|
|
#include <ctype.h>
|
2011-09-23 12:00:45 +04:00
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
#include "list.h"
|
2012-01-26 15:27:00 +04:00
|
|
|
#include "namespaces.h"
|
2011-09-23 12:00:45 +04:00
|
|
|
#include "compiler.h"
|
|
|
|
#include "crtools.h"
|
|
|
|
#include "util.h"
|
2011-12-26 22:12:03 +04:00
|
|
|
#include "sockets.h"
|
2011-09-23 12:00:45 +04:00
|
|
|
#include "image.h"
|
2012-01-31 11:29:23 +03:00
|
|
|
#include "uts_ns.h"
|
2012-01-31 22:29:11 +04:00
|
|
|
#include "ipc_ns.h"
|
2012-06-26 14:51:00 +04:00
|
|
|
#include "pstree.h"
|
2011-09-23 12:00:45 +04:00
|
|
|
|
2012-07-12 13:06:00 +04:00
|
|
|
#include "protobuf.h"
|
|
|
|
#include "protobuf/fdinfo.pb-c.h"
|
2012-07-17 07:17:02 +04:00
|
|
|
#include "protobuf/regfile.pb-c.h"
|
2012-07-17 07:17:51 +04:00
|
|
|
#include "protobuf/ghost-file.pb-c.h"
|
2012-07-12 13:06:00 +04:00
|
|
|
|
2011-11-21 20:27:47 +04:00
|
|
|
#define DEF_PAGES_PER_LINE 6
|
|
|
|
|
2011-09-23 12:00:45 +04:00
|
|
|
#ifndef CONFIG_X86_64
|
|
|
|
# error No x86-32 support yet
|
|
|
|
#endif
|
|
|
|
|
2011-12-05 15:57:47 +04:00
|
|
|
|
2012-03-02 00:59:59 +04:00
|
|
|
#define PR_SYMBOL(sym) \
|
2012-02-29 16:07:11 +03:00
|
|
|
(isprint(sym) ? sym : '.')
|
2011-12-05 15:57:47 +04:00
|
|
|
|
2011-09-23 12:00:45 +04:00
|
|
|
#define pr_regs4(s, n1, n2, n3, n4) \
|
2012-04-13 19:44:00 +04:00
|
|
|
pr_msg("%8s: 0x%16lx " \
|
2012-04-13 19:44:00 +04:00
|
|
|
"%8s: 0x%16lx " \
|
|
|
|
"%8s: 0x%16lx " \
|
|
|
|
"%8s: 0x%16lx\n", \
|
2012-03-02 00:59:59 +04:00
|
|
|
#n1, s.n1, \
|
|
|
|
#n2, s.n2, \
|
|
|
|
#n3, s.n3, \
|
|
|
|
#n4, s.n4)
|
2011-09-23 12:00:45 +04:00
|
|
|
|
|
|
|
#define pr_regs3(s, n1, n2, n3) \
|
2012-04-13 19:44:00 +04:00
|
|
|
pr_msg("%8s: 0x%16lx " \
|
2012-04-13 19:44:00 +04:00
|
|
|
"%8s: 0x%16lx " \
|
|
|
|
"%8s: 0x%16lx\n", \
|
2012-03-02 00:59:59 +04:00
|
|
|
#n1, s.n1, \
|
|
|
|
#n2, s.n2, \
|
|
|
|
#n3, s.n3)
|
2011-09-23 12:00:45 +04:00
|
|
|
|
|
|
|
static char local_buf[PAGE_SIZE];
|
|
|
|
static LIST_HEAD(pstree_list);
|
|
|
|
|
2012-03-24 15:38:18 +04:00
|
|
|
static char *fdtype2s(u8 type)
|
|
|
|
{
|
|
|
|
static char und[4];
|
|
|
|
static char *fdtypes[] = {
|
|
|
|
[FDINFO_REG] = "reg",
|
2012-03-27 12:42:59 +04:00
|
|
|
[FDINFO_INETSK] = "isk",
|
2012-04-05 21:31:13 +04:00
|
|
|
[FDINFO_PIPE] = "pipe",
|
2012-06-26 02:36:13 +04:00
|
|
|
[FDINFO_FIFO] = "fifo",
|
2012-04-06 19:27:08 +04:00
|
|
|
[FDINFO_UNIXSK] = "usk",
|
2012-05-04 13:38:00 +04:00
|
|
|
[FDINFO_EVENTFD] = "efd",
|
2012-05-04 13:38:00 +04:00
|
|
|
[FDINFO_EVENTPOLL] = "epl",
|
2012-05-04 13:38:00 +04:00
|
|
|
[FDINFO_INOTIFY] = "ify",
|
2012-03-24 15:38:18 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
if (type > FDINFO_UND && type < FD_INFO_MAX)
|
|
|
|
return fdtypes[type];
|
2012-04-05 21:31:13 +04:00
|
|
|
snprintf(und, sizeof(und), "x%03d\n", (int)type);
|
2012-03-24 15:38:18 +04:00
|
|
|
return und;
|
|
|
|
}
|
|
|
|
|
2012-03-27 12:01:14 +04:00
|
|
|
void show_files(int fd_files, struct cr_options *o)
|
2011-09-23 12:00:45 +04:00
|
|
|
{
|
2012-01-12 15:16:33 +04:00
|
|
|
pr_img_head(CR_FD_FDINFO);
|
2011-09-23 12:00:45 +04:00
|
|
|
|
2011-12-05 15:57:47 +04:00
|
|
|
while (1) {
|
2012-07-12 13:06:00 +04:00
|
|
|
FdinfoEntry *e;
|
|
|
|
int ret = pb_read_eof(fd_files, &e, fdinfo_entry);
|
2012-01-22 20:20:40 +04:00
|
|
|
if (ret <= 0)
|
2011-12-05 15:57:47 +04:00
|
|
|
goto out;
|
2012-07-12 13:06:00 +04:00
|
|
|
pr_msg("type: %-5s fd: %-5d id: %#x flags %#x\n",
|
|
|
|
fdtype2s(e->type), e->fd, e->id, e->flags);
|
|
|
|
fdinfo_entry__free_unpacked(e, NULL);
|
2012-03-25 20:24:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
pr_img_tail(CR_FD_FDINFO);
|
|
|
|
}
|
|
|
|
|
2012-04-10 22:54:00 +04:00
|
|
|
void show_fown_cont(fown_t *fown)
|
2012-04-10 22:54:00 +04:00
|
|
|
{
|
2012-04-24 15:20:24 +04:00
|
|
|
pr_msg("fown: uid: %#x euid: %#x signum: %#x pid_type: %#x pid: %u",
|
2012-04-10 22:54:00 +04:00
|
|
|
fown->uid, fown->euid, fown->signum, fown->pid_type, fown->pid);
|
|
|
|
}
|
|
|
|
|
2012-03-27 12:01:14 +04:00
|
|
|
void show_reg_files(int fd_reg_files, struct cr_options *o)
|
2012-03-25 20:24:53 +04:00
|
|
|
{
|
2012-07-17 07:17:02 +04:00
|
|
|
local_buf[0] = 0;
|
2012-03-25 20:24:53 +04:00
|
|
|
|
|
|
|
pr_img_head(CR_FD_REG_FILES);
|
|
|
|
while (1) {
|
2012-07-17 07:17:02 +04:00
|
|
|
RegFileEntry *rfe;
|
2012-03-25 20:24:53 +04:00
|
|
|
int ret;
|
|
|
|
|
2012-07-17 07:17:02 +04:00
|
|
|
ret = pb_read_eof(fd_reg_files, &rfe, reg_file_entry);
|
2012-03-25 20:24:53 +04:00
|
|
|
if (ret <= 0)
|
2012-07-17 07:17:02 +04:00
|
|
|
break;
|
2012-01-12 21:54:38 +04:00
|
|
|
|
2012-07-17 07:17:02 +04:00
|
|
|
pr_msg("id: 0x%8x flags: 0x%4x pos: 0x%lx",
|
|
|
|
rfe->id, rfe->flags, rfe->pos);
|
|
|
|
if (rfe->name)
|
|
|
|
pr_msg(" --> %s", rfe->name);
|
2012-03-02 00:59:59 +04:00
|
|
|
pr_msg("\n");
|
2012-07-17 07:17:02 +04:00
|
|
|
reg_file_entry__free_unpacked(rfe, NULL);
|
2011-12-05 15:57:47 +04:00
|
|
|
}
|
2012-03-25 20:24:53 +04:00
|
|
|
pr_img_tail(CR_FD_REG_FILES);
|
2011-12-05 15:57:47 +04:00
|
|
|
}
|
|
|
|
|
2012-04-13 17:54:36 +04:00
|
|
|
static inline char *remap_id_type(u32 id)
|
|
|
|
{
|
|
|
|
if (id & REMAP_GHOST)
|
|
|
|
return "ghost";
|
|
|
|
else
|
|
|
|
return "real";
|
|
|
|
}
|
|
|
|
|
|
|
|
void show_remap_files(int fd, struct cr_options *o)
|
|
|
|
{
|
|
|
|
struct remap_file_path_entry rfe;
|
|
|
|
|
|
|
|
pr_img_head(CR_FD_REMAP_FPATH);
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = read_img_eof(fd, &rfe);
|
|
|
|
if (ret <= 0)
|
|
|
|
break;
|
|
|
|
|
2012-04-24 15:20:24 +04:00
|
|
|
pr_msg("%#x -> %#x (%s)\n", rfe.orig_id,
|
2012-04-13 17:54:36 +04:00
|
|
|
(rfe.remap_id & ~REMAP_GHOST),
|
|
|
|
remap_id_type(rfe.remap_id));
|
|
|
|
}
|
|
|
|
|
|
|
|
pr_img_tail(CR_FD_REMAP_FPATH);
|
|
|
|
}
|
|
|
|
|
|
|
|
void show_ghost_file(int fd, struct cr_options *o)
|
|
|
|
{
|
2012-07-17 07:17:51 +04:00
|
|
|
GhostFileEntry *gfe;
|
2012-04-13 17:54:36 +04:00
|
|
|
|
|
|
|
pr_img_head(CR_FD_GHOST_FILE);
|
2012-07-17 07:17:51 +04:00
|
|
|
if (pb_read_eof(fd, &gfe, ghost_file_entry) > 0) {
|
|
|
|
pr_msg("uid %u god %u mode %#x\n", gfe->uid, gfe->gid, gfe->mode);
|
|
|
|
ghost_file_entry__free_unpacked(gfe, NULL);
|
|
|
|
}
|
2012-04-13 17:54:36 +04:00
|
|
|
pr_img_tail(CR_FD_GHOST_FILE);
|
|
|
|
}
|
|
|
|
|
2012-06-26 02:36:13 +04:00
|
|
|
void __show_pipes_data(int fd, struct cr_options *o)
|
2012-04-05 20:02:00 +04:00
|
|
|
{
|
|
|
|
struct pipe_data_entry e;
|
|
|
|
|
|
|
|
while (1) {
|
2012-06-26 02:36:13 +04:00
|
|
|
if (read_img_eof(fd, &e) <= 0)
|
|
|
|
break;
|
2012-07-12 06:57:20 +04:00
|
|
|
pr_msg("pipeid: 0x%8x bytes: 0x%8x\n", e.pipe_id, e.bytes);
|
|
|
|
lseek(fd, e.bytes, SEEK_CUR);
|
2012-04-05 20:02:00 +04:00
|
|
|
}
|
2012-06-26 02:36:13 +04:00
|
|
|
}
|
2012-04-05 20:02:00 +04:00
|
|
|
|
2012-06-26 02:36:13 +04:00
|
|
|
void show_pipes_data(int fd_pipes, struct cr_options *o)
|
|
|
|
{
|
|
|
|
pr_img_head(CR_FD_PIPES_DATA);
|
|
|
|
__show_pipes_data(fd_pipes, o);
|
2012-06-22 19:58:00 +04:00
|
|
|
pr_img_tail(CR_FD_PIPES_DATA);
|
2012-04-05 20:02:00 +04:00
|
|
|
}
|
|
|
|
|
2012-03-27 12:01:14 +04:00
|
|
|
void show_pipes(int fd_pipes, struct cr_options *o)
|
2011-12-05 15:57:47 +04:00
|
|
|
{
|
|
|
|
struct pipe_entry e;
|
|
|
|
int ret;
|
|
|
|
|
2012-01-12 15:16:33 +04:00
|
|
|
pr_img_head(CR_FD_PIPES);
|
2011-12-05 15:57:47 +04:00
|
|
|
|
|
|
|
while (1) {
|
2012-01-22 20:20:40 +04:00
|
|
|
ret = read_img_eof(fd_pipes, &e);
|
|
|
|
if (ret <= 0)
|
2011-12-05 15:57:47 +04:00
|
|
|
goto out;
|
2012-04-13 19:44:00 +04:00
|
|
|
pr_msg("id: 0x%8x pipeid: 0x%8x flags: 0x%8x ",
|
2012-04-05 20:02:00 +04:00
|
|
|
e.id, e.pipe_id, e.flags);
|
2012-04-10 22:54:00 +04:00
|
|
|
show_fown_cont(&e.fown);
|
|
|
|
pr_msg("\n");
|
2011-12-05 15:57:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2012-01-12 15:16:33 +04:00
|
|
|
pr_img_tail(CR_FD_PIPES);
|
2011-12-05 15:57:47 +04:00
|
|
|
}
|
|
|
|
|
2012-06-26 02:36:13 +04:00
|
|
|
void show_fifo_data(int fd, struct cr_options *o)
|
|
|
|
{
|
|
|
|
pr_img_head(CR_FD_FIFO_DATA);
|
|
|
|
__show_pipes_data(fd, o);
|
|
|
|
pr_img_tail(CR_FD_FIFO_DATA);
|
|
|
|
}
|
|
|
|
|
|
|
|
void show_fifo(int fd, struct cr_options *o)
|
|
|
|
{
|
|
|
|
struct fifo_entry e;
|
|
|
|
|
|
|
|
pr_img_head(CR_FD_FIFO);
|
|
|
|
while (1) {
|
|
|
|
if (read_img_eof(fd, &e) <= 0)
|
|
|
|
break;
|
|
|
|
pr_msg("id: 0x%8x pipeid: 0x%8x\n", e.id, e.pipe_id);
|
|
|
|
}
|
|
|
|
pr_img_tail(CR_FD_FIFO);
|
|
|
|
}
|
|
|
|
|
2012-04-09 13:41:05 +04:00
|
|
|
void show_fs(int fd_fs, struct cr_options *o)
|
|
|
|
{
|
|
|
|
struct fs_entry fe;
|
|
|
|
|
|
|
|
pr_img_head(CR_FD_FS);
|
|
|
|
|
2012-04-09 13:52:42 +04:00
|
|
|
if (read_img(fd_fs, &fe) > 0) {
|
2012-04-24 15:20:24 +04:00
|
|
|
pr_msg("CWD : %#x\n", fe.cwd_id);
|
|
|
|
pr_msg("ROOT: %#x\n", fe.root_id);
|
2012-04-09 13:52:42 +04:00
|
|
|
}
|
2012-04-09 13:41:05 +04:00
|
|
|
|
|
|
|
pr_img_tail(CR_FD_FS);
|
|
|
|
}
|
|
|
|
|
2012-03-27 12:01:14 +04:00
|
|
|
void show_vmas(int fd_vma, struct cr_options *o)
|
2011-12-05 15:57:47 +04:00
|
|
|
{
|
|
|
|
struct vma_area vma_area = {};
|
|
|
|
struct vma_entry ve;
|
|
|
|
|
2012-03-21 14:22:00 +04:00
|
|
|
pr_img_head(CR_FD_VMAS);
|
|
|
|
|
2011-12-05 15:57:47 +04:00
|
|
|
while (1) {
|
2012-03-21 14:22:00 +04:00
|
|
|
int ret;
|
2011-12-05 15:57:47 +04:00
|
|
|
|
2012-03-21 14:22:00 +04:00
|
|
|
ret = read_img_eof(fd_vma, &ve);
|
|
|
|
if (ret <= 0)
|
2011-12-05 15:57:47 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* Simply in a sake of fancy printing */
|
|
|
|
vma_area.vma = ve;
|
2012-03-02 00:59:59 +04:00
|
|
|
pr_msg_vma(&vma_area);
|
2011-12-05 15:57:47 +04:00
|
|
|
}
|
2012-03-21 14:22:00 +04:00
|
|
|
|
|
|
|
pr_img_tail(CR_FD_VMAS);
|
2011-12-05 15:57:47 +04:00
|
|
|
}
|
|
|
|
|
2012-04-29 09:05:21 +04:00
|
|
|
static int nice_width_for(unsigned long addr)
|
|
|
|
{
|
|
|
|
int ret = 3;
|
|
|
|
|
|
|
|
while (addr) {
|
|
|
|
addr >>= 4;
|
|
|
|
ret++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-02-29 16:07:11 +03:00
|
|
|
void print_data(unsigned long addr, unsigned char *data, size_t size)
|
|
|
|
{
|
2012-04-29 09:05:21 +04:00
|
|
|
int i, j, addr_len;
|
|
|
|
|
|
|
|
addr_len = nice_width_for(addr + size);
|
2012-02-29 16:07:11 +03:00
|
|
|
|
|
|
|
for (i = 0; i < size; i+= 16) {
|
2012-04-29 09:05:21 +04:00
|
|
|
pr_msg("%#0*lx: ", addr_len, addr + i);
|
2012-02-29 16:07:11 +03:00
|
|
|
for (j = 0; j < 8; j++)
|
2012-04-13 19:44:00 +04:00
|
|
|
pr_msg("0x%02x ", data[i + j]);
|
2012-03-02 00:59:59 +04:00
|
|
|
pr_msg(" ");
|
2012-02-29 16:07:11 +03:00
|
|
|
for (j = 8; j < 16; j++)
|
2012-04-13 19:44:00 +04:00
|
|
|
pr_msg("0x%02x ", data[i + j]);
|
2012-02-29 16:07:11 +03:00
|
|
|
|
2012-03-02 00:59:59 +04:00
|
|
|
pr_msg(" |");
|
2012-02-29 16:07:11 +03:00
|
|
|
for (j = 0; j < 8; j++)
|
2012-03-02 00:59:59 +04:00
|
|
|
pr_msg("%c ", PR_SYMBOL(data[i + j]));
|
|
|
|
pr_msg(" ");
|
2012-02-29 16:07:11 +03:00
|
|
|
for (j = 8; j < 16; j++)
|
2012-03-02 00:59:59 +04:00
|
|
|
pr_msg("%c ", PR_SYMBOL(data[i + j]));
|
2012-02-29 16:07:11 +03:00
|
|
|
|
2012-03-02 00:59:59 +04:00
|
|
|
pr_msg("|\n");
|
2012-02-29 16:07:11 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-27 12:01:14 +04:00
|
|
|
void show_pages(int fd_pages, struct cr_options *o)
|
2011-12-05 15:57:47 +04:00
|
|
|
{
|
2012-01-12 15:16:33 +04:00
|
|
|
pr_img_head(CR_FD_PAGES);
|
2011-12-05 15:57:47 +04:00
|
|
|
|
2012-03-27 12:01:14 +04:00
|
|
|
if (o->show_pages_content) {
|
2011-12-05 15:57:47 +04:00
|
|
|
while (1) {
|
|
|
|
struct page_entry e;
|
|
|
|
|
2012-04-05 12:57:29 +04:00
|
|
|
if (read_img_eof(fd_pages, &e) <= 0)
|
2011-12-05 15:57:47 +04:00
|
|
|
break;
|
|
|
|
|
2012-02-29 16:07:11 +03:00
|
|
|
print_data(e.va, e.data, PAGE_IMAGE_SIZE);
|
2012-03-02 00:59:59 +04:00
|
|
|
pr_msg("\n --- End of page ---\n\n");
|
2011-12-05 15:57:47 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
while (1) {
|
|
|
|
struct page_entry e;
|
2012-05-18 15:39:00 +04:00
|
|
|
int i;
|
2011-12-05 15:57:47 +04:00
|
|
|
|
2012-03-02 00:59:59 +04:00
|
|
|
pr_msg("\t");
|
2011-12-05 15:57:47 +04:00
|
|
|
for (i = 0; i < DEF_PAGES_PER_LINE; i++) {
|
2012-04-05 12:57:29 +04:00
|
|
|
if (read_img_eof(fd_pages, &e) <= 0) {
|
2012-03-02 00:59:59 +04:00
|
|
|
pr_msg("\n");
|
2011-12-05 15:57:47 +04:00
|
|
|
goto out;
|
|
|
|
}
|
2012-04-05 12:57:29 +04:00
|
|
|
|
2012-04-13 19:44:00 +04:00
|
|
|
pr_msg("0x%16lx ", e.va);
|
2011-12-05 15:57:47 +04:00
|
|
|
}
|
2012-03-02 00:59:59 +04:00
|
|
|
pr_msg("\n");
|
2011-12-05 15:57:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2012-01-12 15:16:33 +04:00
|
|
|
pr_img_tail(CR_FD_PAGES);
|
2011-12-05 15:57:47 +04:00
|
|
|
}
|
|
|
|
|
2012-03-27 12:01:14 +04:00
|
|
|
void show_sigacts(int fd_sigacts, struct cr_options *o)
|
2011-12-05 15:57:47 +04:00
|
|
|
{
|
|
|
|
struct sa_entry e;
|
|
|
|
|
2012-01-12 15:16:33 +04:00
|
|
|
pr_img_head(CR_FD_SIGACT);
|
2011-12-05 15:57:47 +04:00
|
|
|
|
|
|
|
while (1) {
|
2012-01-22 20:20:40 +04:00
|
|
|
int ret;
|
2012-01-30 17:06:09 +04:00
|
|
|
|
2012-01-22 20:20:40 +04:00
|
|
|
ret = read_img_eof(fd_sigacts, &e);
|
|
|
|
if (ret <= 0)
|
2011-12-05 15:57:47 +04:00
|
|
|
goto out;
|
2012-04-13 19:44:00 +04:00
|
|
|
pr_msg("sigaction: 0x%016lx mask: 0x%08lx "
|
2012-04-13 19:44:00 +04:00
|
|
|
"flags: 0x%016lx restorer: 0x%016lx\n",
|
2012-03-02 00:59:59 +04:00
|
|
|
(long)e.sigaction,
|
|
|
|
(long)e.mask,
|
|
|
|
(long)e.flags,
|
|
|
|
(long)e.restorer);
|
2011-12-05 15:57:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2012-01-12 15:16:33 +04:00
|
|
|
pr_img_tail(CR_FD_SIGACT);
|
2011-12-05 15:57:47 +04:00
|
|
|
}
|
|
|
|
|
2012-01-24 16:45:19 +04:00
|
|
|
static void show_itimer(char *n, struct itimer_entry *ie)
|
|
|
|
{
|
2012-03-02 00:59:59 +04:00
|
|
|
pr_msg("%s: int %lu.%lu val %lu.%lu\n", n,
|
|
|
|
(unsigned long)ie->isec, (unsigned long)ie->iusec,
|
|
|
|
(unsigned long)ie->vsec, (unsigned long)ie->vusec);
|
2012-01-24 16:45:19 +04:00
|
|
|
}
|
|
|
|
|
2012-03-27 12:01:14 +04:00
|
|
|
void show_itimers(int fd, struct cr_options *o)
|
2012-01-24 16:45:19 +04:00
|
|
|
{
|
|
|
|
struct itimer_entry ie[3];
|
|
|
|
|
|
|
|
pr_img_head(CR_FD_ITIMERS);
|
|
|
|
if (read_img_buf(fd, ie, sizeof(ie)) < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
show_itimer("real", &ie[0]);
|
2012-03-22 21:17:57 +04:00
|
|
|
show_itimer("virt", &ie[1]);
|
|
|
|
show_itimer("prof", &ie[2]);
|
2012-01-24 16:45:19 +04:00
|
|
|
out:
|
|
|
|
pr_img_tail(CR_FD_ITIMERS);
|
|
|
|
}
|
|
|
|
|
2012-01-27 21:43:32 +04:00
|
|
|
static void show_cap(char *name, u32 *v)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2012-03-02 00:59:59 +04:00
|
|
|
pr_msg("%s: ", name);
|
2012-01-27 21:43:32 +04:00
|
|
|
for (i = CR_CAP_SIZE - 1; i >= 0; i--)
|
2012-04-13 19:44:00 +04:00
|
|
|
pr_msg("0x%08x", v[i]);
|
2012-03-02 00:59:59 +04:00
|
|
|
pr_msg("\n");
|
2012-01-27 21:43:32 +04:00
|
|
|
}
|
|
|
|
|
2012-03-27 12:01:14 +04:00
|
|
|
void show_creds(int fd, struct cr_options *o)
|
2012-01-27 21:43:32 +04:00
|
|
|
{
|
|
|
|
struct creds_entry ce;
|
|
|
|
|
|
|
|
pr_img_head(CR_FD_CREDS);
|
|
|
|
if (read_img(fd, &ce) < 0)
|
|
|
|
goto out;
|
|
|
|
|
2012-03-02 00:59:59 +04:00
|
|
|
pr_msg("uid %u euid %u suid %u fsuid %u\n",
|
|
|
|
ce.uid, ce.euid, ce.suid, ce.fsuid);
|
|
|
|
pr_msg("gid %u egid %u sgid %u fsgid %u\n",
|
|
|
|
ce.gid, ce.egid, ce.sgid, ce.fsgid);
|
2012-01-27 21:43:32 +04:00
|
|
|
|
|
|
|
show_cap("Inh", ce.cap_inh);
|
|
|
|
show_cap("Eff", ce.cap_eff);
|
|
|
|
show_cap("Prm", ce.cap_prm);
|
|
|
|
show_cap("Bnd", ce.cap_bnd);
|
|
|
|
|
2012-04-24 15:20:24 +04:00
|
|
|
pr_msg("secbits: %#x\n", ce.secbits);
|
2012-01-27 21:43:32 +04:00
|
|
|
out:
|
|
|
|
pr_img_tail(CR_FD_CREDS);
|
|
|
|
}
|
|
|
|
|
2012-03-27 12:01:14 +04:00
|
|
|
static int show_collect_pstree(int fd_pstree, struct list_head *collect)
|
2011-12-05 15:57:47 +04:00
|
|
|
{
|
|
|
|
struct pstree_entry e;
|
|
|
|
|
2012-01-12 15:16:33 +04:00
|
|
|
pr_img_head(CR_FD_PSTREE);
|
2011-12-05 15:57:47 +04:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
u32 pid;
|
|
|
|
int ret;
|
2012-01-12 21:53:46 +04:00
|
|
|
struct pstree_item *item = NULL;
|
2011-12-05 15:57:47 +04:00
|
|
|
|
2012-01-22 20:20:40 +04:00
|
|
|
ret = read_img_eof(fd_pstree, &e);
|
|
|
|
if (ret <= 0)
|
2011-12-05 15:57:47 +04:00
|
|
|
goto out;
|
2012-05-31 14:50:00 +04:00
|
|
|
pr_msg("pid: %8d ppid %8d pgid: %8d sid %8d nr_threads: %8d\n",
|
|
|
|
e.pid, e.ppid, e.pgid, e.sid, e.nr_threads);
|
2011-12-05 15:57:47 +04:00
|
|
|
|
2012-01-12 21:53:46 +04:00
|
|
|
if (collect) {
|
|
|
|
item = xzalloc(sizeof(struct pstree_item));
|
|
|
|
if (!item)
|
|
|
|
return -1;
|
|
|
|
|
2012-06-22 00:38:00 +04:00
|
|
|
item->pid.virt = e.pid;
|
2012-01-12 21:53:46 +04:00
|
|
|
item->nr_threads = e.nr_threads;
|
|
|
|
item->threads = xzalloc(sizeof(u32) * e.nr_threads);
|
|
|
|
if (!item->threads) {
|
|
|
|
xfree(item);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
list_add_tail(&item->list, collect);
|
|
|
|
}
|
|
|
|
|
2011-12-05 15:57:47 +04:00
|
|
|
if (e.nr_threads) {
|
2012-03-02 00:59:59 +04:00
|
|
|
pr_msg(" \\\n");
|
|
|
|
pr_msg(" --- threads: ");
|
2011-12-05 15:57:47 +04:00
|
|
|
while (e.nr_threads--) {
|
2012-04-07 00:22:00 +04:00
|
|
|
ret = read_img(fd_pstree, &pid);
|
|
|
|
if (ret < 0)
|
2011-12-05 15:57:47 +04:00
|
|
|
goto out;
|
2012-03-02 00:59:59 +04:00
|
|
|
pr_msg(" %6d", pid);
|
2012-01-12 21:53:46 +04:00
|
|
|
if (item)
|
2012-06-22 00:38:00 +04:00
|
|
|
item->threads[e.nr_threads].virt = pid;
|
2011-12-05 15:57:47 +04:00
|
|
|
}
|
2012-03-02 00:59:59 +04:00
|
|
|
pr_msg("\n");
|
2011-12-05 15:57:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2012-01-12 15:16:33 +04:00
|
|
|
pr_img_tail(CR_FD_PSTREE);
|
2012-01-12 21:53:46 +04:00
|
|
|
return 0;
|
2011-12-05 15:57:47 +04:00
|
|
|
}
|
|
|
|
|
2012-03-27 12:01:14 +04:00
|
|
|
void show_pstree(int fd_pstree, struct cr_options *o)
|
|
|
|
{
|
|
|
|
show_collect_pstree(fd_pstree, NULL);
|
|
|
|
}
|
|
|
|
|
2011-12-05 15:57:47 +04:00
|
|
|
static void show_core_regs(int fd_core)
|
|
|
|
{
|
|
|
|
struct user_regs_entry regs;
|
|
|
|
|
2012-03-02 00:59:59 +04:00
|
|
|
pr_msg("\n\t---[GP registers set]---\n");
|
2011-09-23 12:00:45 +04:00
|
|
|
|
2012-01-22 20:16:33 +04:00
|
|
|
lseek(fd_core, GET_FILE_OFF(struct core_entry, arch.gpregs), SEEK_SET);
|
2011-09-23 12:00:45 +04:00
|
|
|
|
2012-01-22 20:20:40 +04:00
|
|
|
if (read_img(fd_core, ®s) < 0)
|
|
|
|
goto err;
|
2011-09-23 12:00:45 +04:00
|
|
|
|
|
|
|
pr_regs4(regs, cs, ip, ds, es);
|
|
|
|
pr_regs4(regs, ss, sp, fs, gs);
|
|
|
|
pr_regs4(regs, di, si, dx, cx);
|
|
|
|
pr_regs4(regs, ax, r8, r9, r10);
|
|
|
|
pr_regs4(regs, r11, r12, r13, r14);
|
|
|
|
pr_regs3(regs, r15, bp, bx);
|
|
|
|
pr_regs4(regs, orig_ax, flags, fs_base, gs_base);
|
2012-03-02 00:59:59 +04:00
|
|
|
pr_msg("\n");
|
2011-09-23 12:00:45 +04:00
|
|
|
|
|
|
|
err:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-22 20:24:04 +04:00
|
|
|
static inline char *task_state_str(int state)
|
|
|
|
{
|
|
|
|
switch (state) {
|
|
|
|
case TASK_ALIVE:
|
|
|
|
return "running/sleeping";
|
|
|
|
case TASK_DEAD:
|
|
|
|
return "zombie";
|
|
|
|
default:
|
|
|
|
return "UNKNOWN";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-05 15:57:47 +04:00
|
|
|
static void show_core_rest(int fd_core)
|
2011-10-01 13:24:34 +04:00
|
|
|
{
|
2012-01-22 20:20:40 +04:00
|
|
|
struct task_core_entry tc;
|
2011-10-01 13:24:34 +04:00
|
|
|
|
2012-01-22 20:20:40 +04:00
|
|
|
lseek(fd_core, GET_FILE_OFF(struct core_entry, tc), SEEK_SET);
|
|
|
|
if (read_img(fd_core, &tc) < 0)
|
|
|
|
goto err;
|
2011-10-12 18:05:07 +04:00
|
|
|
|
2012-03-02 00:59:59 +04:00
|
|
|
pr_msg("\n\t---[Task parameters]---\n");
|
2012-04-24 15:20:24 +04:00
|
|
|
pr_msg("\tPersonality: %#x\n", tc.personality);
|
2012-03-02 00:59:59 +04:00
|
|
|
pr_msg("\tCommand: %s\n", tc.comm);
|
|
|
|
pr_msg("\tState: %d (%s)\n",
|
|
|
|
(int)tc.task_state,
|
|
|
|
task_state_str((int)tc.task_state));
|
|
|
|
|
|
|
|
pr_msg("\t Exit code: %u\n",
|
|
|
|
(unsigned int)tc.exit_code);
|
|
|
|
|
2012-04-13 19:44:00 +04:00
|
|
|
pr_msg("\tBlkSig: 0x%lx\n", tc.blk_sigset);
|
2012-03-02 00:59:59 +04:00
|
|
|
pr_msg("\n");
|
2011-11-21 20:19:35 +04:00
|
|
|
|
|
|
|
err:
|
2011-12-05 15:57:47 +04:00
|
|
|
return;
|
2011-11-21 20:19:35 +04:00
|
|
|
}
|
|
|
|
|
2012-04-09 18:02:00 +04:00
|
|
|
static void show_core_ids(int fd)
|
|
|
|
{
|
|
|
|
struct core_ids_entry cie;
|
|
|
|
|
|
|
|
lseek(fd, GET_FILE_OFF(struct core_entry, ids), SEEK_SET);
|
|
|
|
if (read_img(fd, &cie) < 0)
|
|
|
|
goto err;
|
|
|
|
|
2012-04-24 15:20:24 +04:00
|
|
|
pr_msg("\tVM: %#x\n", cie.vm_id);
|
|
|
|
pr_msg("\tFS: %#x\n", cie.fs_id);
|
|
|
|
pr_msg("\tFILES: %#x\n", cie.files_id);
|
|
|
|
pr_msg("\tSIGHAND: %#x\n", cie.sighand_id);
|
2012-04-09 18:02:00 +04:00
|
|
|
err:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-27 12:01:14 +04:00
|
|
|
void show_core(int fd_core, struct cr_options *o)
|
2011-09-23 12:00:45 +04:00
|
|
|
{
|
2011-12-05 15:57:47 +04:00
|
|
|
struct stat stat;
|
|
|
|
bool is_thread;
|
2011-09-23 12:00:45 +04:00
|
|
|
|
2011-12-05 15:57:47 +04:00
|
|
|
if (fstat(fd_core, &stat)) {
|
2012-01-31 15:13:05 +04:00
|
|
|
pr_perror("Can't get stat on core file");
|
2011-12-05 15:57:47 +04:00
|
|
|
goto out;
|
2011-09-23 12:00:45 +04:00
|
|
|
}
|
|
|
|
|
2011-12-05 15:57:47 +04:00
|
|
|
is_thread = (stat.st_size == GET_FILE_OFF_AFTER(struct core_entry));
|
2011-09-23 12:00:45 +04:00
|
|
|
|
2012-01-12 15:16:33 +04:00
|
|
|
if (is_thread)
|
|
|
|
pr_img_head(CR_FD_CORE, " (thread)");
|
|
|
|
else
|
|
|
|
pr_img_head(CR_FD_CORE);
|
2011-09-23 12:00:45 +04:00
|
|
|
|
2011-12-05 15:57:47 +04:00
|
|
|
show_core_regs(fd_core);
|
|
|
|
show_core_rest(fd_core);
|
2012-04-09 18:02:00 +04:00
|
|
|
show_core_ids(fd_core);
|
2011-09-23 12:00:45 +04:00
|
|
|
out:
|
2012-01-12 15:16:33 +04:00
|
|
|
pr_img_tail(CR_FD_CORE);
|
2011-09-23 12:00:45 +04:00
|
|
|
}
|
|
|
|
|
2012-04-09 14:51:37 +04:00
|
|
|
void show_mm(int fd_mm, struct cr_options *o)
|
|
|
|
{
|
|
|
|
struct mm_entry mme;
|
|
|
|
|
|
|
|
pr_img_head(CR_FD_MM);
|
|
|
|
|
|
|
|
if (read_img(fd_mm, &mme) < 0)
|
|
|
|
goto out;
|
|
|
|
|
2012-04-13 19:44:00 +04:00
|
|
|
pr_msg("\tBrk: 0x%lx\n", mme.mm_brk);
|
|
|
|
pr_msg("\tStart code: 0x%lx\n", mme.mm_start_code);
|
|
|
|
pr_msg("\tEnd code: 0x%lx\n", mme.mm_end_code);
|
|
|
|
pr_msg("\tStart stack: 0x%lx\n", mme.mm_start_stack);
|
|
|
|
pr_msg("\tStart data: 0x%lx\n", mme.mm_start_data);
|
|
|
|
pr_msg("\tEnd data: 0x%lx\n", mme.mm_end_data);
|
|
|
|
pr_msg("\tStart brk: 0x%lx\n", mme.mm_start_brk);
|
|
|
|
pr_msg("\tArg start: 0x%lx\n", mme.mm_arg_start);
|
|
|
|
pr_msg("\tArg end: 0x%lx\n", mme.mm_arg_end);
|
|
|
|
pr_msg("\tEnv start: 0x%lx\n", mme.mm_env_start);
|
|
|
|
pr_msg("\tEnv end: 0x%lx\n", mme.mm_env_end);
|
2012-04-24 15:20:24 +04:00
|
|
|
pr_msg("\tExe file ID %#x\n", mme.exe_file_id);
|
2012-04-09 14:51:37 +04:00
|
|
|
out:
|
|
|
|
pr_img_tail(CR_FD_MM);
|
|
|
|
}
|
|
|
|
|
2011-12-05 15:57:47 +04:00
|
|
|
static int cr_parse_file(struct cr_options *opts)
|
2011-09-23 12:00:45 +04:00
|
|
|
{
|
2011-12-05 15:57:47 +04:00
|
|
|
u32 magic;
|
2012-03-27 12:01:14 +04:00
|
|
|
int fd = -1, ret = -1, i;
|
2011-09-23 12:00:45 +04:00
|
|
|
|
2011-12-05 15:57:47 +04:00
|
|
|
fd = open(opts->show_dump_file, O_RDONLY);
|
|
|
|
if (fd < 0) {
|
2012-01-31 15:13:05 +04:00
|
|
|
pr_perror("Can't open %s", opts->show_dump_file);
|
2011-12-05 15:57:47 +04:00
|
|
|
goto err;
|
2011-09-23 12:00:45 +04:00
|
|
|
}
|
|
|
|
|
2012-01-22 20:20:40 +04:00
|
|
|
if (read_img(fd, &magic) < 0)
|
|
|
|
goto err;
|
2011-12-05 15:57:47 +04:00
|
|
|
|
2012-03-27 12:01:14 +04:00
|
|
|
for (i = 0; i < CR_FD_MAX; i++)
|
|
|
|
if (fdset_template[i].magic == magic)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (i == CR_FD_MAX) {
|
2012-04-24 15:20:24 +04:00
|
|
|
pr_err("Unknown magic %#x in %s\n",
|
2012-03-27 12:01:14 +04:00
|
|
|
magic, opts->show_dump_file);
|
2011-12-05 15:57:47 +04:00
|
|
|
goto err;
|
2011-09-23 12:00:45 +04:00
|
|
|
}
|
|
|
|
|
2012-03-27 12:01:14 +04:00
|
|
|
if (!fdset_template[i].show) {
|
2012-04-24 15:20:24 +04:00
|
|
|
pr_err("No handler for %#x/%s\n",
|
2012-03-27 12:01:14 +04:00
|
|
|
magic, opts->show_dump_file);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
fdset_template[i].show(fd, opts);
|
|
|
|
ret = 0;
|
2011-12-05 15:57:47 +04:00
|
|
|
err:
|
|
|
|
close_safe(&fd);
|
|
|
|
return ret;
|
2011-09-23 12:00:45 +04:00
|
|
|
}
|
|
|
|
|
2012-03-27 11:04:23 +04:00
|
|
|
static int cr_show_all(struct cr_options *opts)
|
2011-09-23 12:00:45 +04:00
|
|
|
{
|
2012-05-31 14:50:00 +04:00
|
|
|
struct pstree_item *item = NULL, *tmp;
|
2011-12-05 15:57:47 +04:00
|
|
|
LIST_HEAD(pstree_list);
|
2012-03-27 11:04:23 +04:00
|
|
|
int i, ret = -1, fd, pid;
|
2011-09-23 12:00:45 +04:00
|
|
|
|
2012-03-26 17:37:41 +04:00
|
|
|
fd = open_image_ro(CR_FD_PSTREE);
|
|
|
|
if (fd < 0)
|
2011-09-23 12:00:45 +04:00
|
|
|
goto out;
|
|
|
|
|
2012-03-27 12:01:14 +04:00
|
|
|
ret = show_collect_pstree(fd, &pstree_list);
|
2011-09-23 12:00:45 +04:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
2012-03-26 17:37:41 +04:00
|
|
|
close(fd);
|
|
|
|
|
2012-03-26 17:38:59 +04:00
|
|
|
fd = open_image_ro(CR_FD_SK_QUEUES);
|
2012-03-26 17:37:41 +04:00
|
|
|
if (fd < 0)
|
2012-03-23 18:42:00 +04:00
|
|
|
goto out;
|
|
|
|
|
2012-03-27 12:01:14 +04:00
|
|
|
show_sk_queues(fd, opts);
|
2012-03-26 17:37:41 +04:00
|
|
|
close(fd);
|
2011-09-23 12:00:45 +04:00
|
|
|
|
2012-06-22 00:38:00 +04:00
|
|
|
pid = list_first_entry(&pstree_list, struct pstree_item, list)->pid.virt;
|
2012-03-27 12:01:14 +04:00
|
|
|
ret = try_show_namespaces(pid, opts);
|
2012-01-26 15:27:00 +04:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
|
2011-09-23 12:00:45 +04:00
|
|
|
list_for_each_entry(item, &pstree_list, list) {
|
2012-03-26 17:37:41 +04:00
|
|
|
struct cr_fdset *cr_fdset = NULL;
|
2011-09-23 12:00:45 +04:00
|
|
|
|
2012-06-22 00:38:00 +04:00
|
|
|
cr_fdset = cr_task_fdset_open(item->pid.virt, O_SHOW);
|
2011-09-23 12:00:45 +04:00
|
|
|
if (!cr_fdset)
|
|
|
|
goto out;
|
|
|
|
|
2012-03-27 12:01:14 +04:00
|
|
|
show_core(fdset_fd(cr_fdset, CR_FD_CORE), opts);
|
2011-10-20 23:11:31 +04:00
|
|
|
|
|
|
|
if (item->nr_threads > 1) {
|
2012-03-27 12:01:14 +04:00
|
|
|
int fd_th;
|
2011-10-20 23:11:31 +04:00
|
|
|
|
|
|
|
for (i = 0; i < item->nr_threads; i++) {
|
|
|
|
|
2012-06-22 00:38:00 +04:00
|
|
|
if (item->threads[i].virt == item->pid.virt)
|
2011-10-20 23:11:31 +04:00
|
|
|
continue;
|
|
|
|
|
2012-03-26 17:42:28 +04:00
|
|
|
fd_th = open_image_ro(CR_FD_CORE, item->threads[i]);
|
|
|
|
if (fd_th < 0)
|
2011-10-20 23:11:31 +04:00
|
|
|
goto out;
|
|
|
|
|
2012-03-02 00:59:59 +04:00
|
|
|
pr_msg("\n");
|
2012-06-22 00:38:00 +04:00
|
|
|
pr_msg("Thread: %d\n", item->threads[i].virt);
|
2012-03-02 00:59:59 +04:00
|
|
|
pr_msg("----------------------------------------\n");
|
2011-10-20 23:11:31 +04:00
|
|
|
|
2012-03-27 12:01:14 +04:00
|
|
|
show_core(fd_th, opts);
|
2011-10-20 23:11:31 +04:00
|
|
|
|
2012-03-02 00:59:59 +04:00
|
|
|
pr_msg("----------------------------------------\n");
|
2011-10-20 23:11:31 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-27 12:01:14 +04:00
|
|
|
for (i = _CR_FD_TASK_FROM + 1; i < _CR_FD_TASK_TO; i++)
|
|
|
|
if (i != CR_FD_CORE && fdset_template[i].show)
|
|
|
|
fdset_template[i].show(fdset_fd(cr_fdset, i), opts);
|
2012-01-27 21:43:32 +04:00
|
|
|
|
2012-01-12 21:25:19 +04:00
|
|
|
close_cr_fdset(&cr_fdset);
|
2011-09-23 12:00:45 +04:00
|
|
|
|
2011-10-04 01:50:19 +04:00
|
|
|
if (opts->leader_only)
|
2011-09-23 12:00:45 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2012-05-31 14:50:00 +04:00
|
|
|
list_for_each_entry_safe(item, tmp, &pstree_list, list) {
|
|
|
|
list_del(&item->list);
|
|
|
|
xfree(item->threads);
|
|
|
|
xfree(item);
|
|
|
|
}
|
2011-09-23 12:00:45 +04:00
|
|
|
return ret;
|
|
|
|
}
|
2011-12-05 15:57:47 +04:00
|
|
|
|
2012-03-27 11:04:23 +04:00
|
|
|
int cr_show(struct cr_options *opts)
|
2011-12-05 15:57:47 +04:00
|
|
|
{
|
2011-12-28 20:38:00 +04:00
|
|
|
if (opts->show_dump_file)
|
2011-12-05 15:57:47 +04:00
|
|
|
return cr_parse_file(opts);
|
|
|
|
|
2012-03-27 11:04:23 +04:00
|
|
|
return cr_show_all(opts);
|
2011-12-05 15:57:47 +04:00
|
|
|
}
|