From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 47700 invoked by alias); 9 Feb 2017 13:06:10 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 46411 invoked by uid 89); 9 Feb 2017 13:06:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=1.3 required=5.0 tests=BAYES_50,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=no version=3.3.2 spammy=Core, *next, linux-kernel, linuxkernel X-HELO: mail-wm0-f67.google.com Received: from mail-wm0-f67.google.com (HELO mail-wm0-f67.google.com) (74.125.82.67) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 09 Feb 2017 13:06:06 +0000 Received: by mail-wm0-f67.google.com with SMTP id u63so2787501wmu.2 for ; Thu, 09 Feb 2017 05:06:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=z/Sfe1/7ILATBp3K+L8rldL8JRsky8sOKW9hxfYe/mI=; b=oLyM3BnQi/AYXrNU7M/fLfx8WtsTIvA/mtYYXrS+BMcHhb5bxnVmUZhBxTKkgbFJgi y0bWyhclftHc1OD4eG/JVFeJPED2z+1xGFMfetepazzXCsEHy98fZanCKNqk10r9dE1y mAOddQzaLDO9q4P2qFCXOptnrGk3iauPmiKtDJUyiEizsFjH85nBttgMv4OAa3Gw7TAj oEjixp4dgxkZyM9Ac4Gv3Sl1TXHqlWn9yr9bkyulVMd89IVMhvJN0vdI5WCFs43b8Kun 7IiuB7i6tqQYsTrhELdhJ7L2LNvMnY/Ls5BOL9g8OwOXOB34Cu5FubOVxN7PtureLPyI kNFA== X-Gm-Message-State: AMke39nHs5VD8+vttfIB/ESwuOccKSutVDerVw+/9po1WpoqGjc/+zaocQnfibclCVDIwA== X-Received: by 10.28.69.28 with SMTP id s28mr20841914wma.40.1486645564537; Thu, 09 Feb 2017 05:06:04 -0800 (PST) Received: from E107787-LIN ([194.214.185.158]) by smtp.gmail.com with ESMTPSA id v128sm8799640wmv.2.2017.02.09.05.06.03 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Thu, 09 Feb 2017 05:06:03 -0800 (PST) From: Yao Qi To: Yao Qi Cc: Philipp Rudo , gdb-patches@sourceware.org, peter.griffin@linaro.org, yao.qi@arm.com, arnez@linux.vnet.ibm.com Subject: Re: [RFC 3/7] Add basic Linux kernel support References: <20170112113217.48852-1-prudo@linux.vnet.ibm.com> <20170112113217.48852-4-prudo@linux.vnet.ibm.com> <20170207105403.GA1630@E107787-LIN> Date: Thu, 09 Feb 2017 13:06:00 -0000 In-Reply-To: <20170207105403.GA1630@E107787-LIN> (Yao Qi's message of "Tue, 7 Feb 2017 10:54:03 +0000") Message-ID: <86wpczo6o9.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2017-02/txt/msg00223.txt.bz2 Yao Qi writes: > I am playing your first three patches on x86_64 with some hacks. > I write a small program with the same linux kernel "signature", and > want GDB treat it as a linux kernel. > I make some progress on writing such small test case, see the code below. I hacked lk_try_push_target not to do the sanity check, and not to call lk_try_push_target in lk_observer_inferior_created, so that I can push this target layer when I want. (gdb) break stop^M Breakpoint 2 at 0x400711: file /home/yao/SourceCode/gnu/gdb/git/gdb/testsui= te/gdb.base/linux-kernel.c, line 104.^M (gdb) continue^M Continuing.^M ^M Breakpoint 2, stop () at /home/yao/SourceCode/gnu/gdb/git/gdb/testsuite/gdb= .base/linux-kernel.c:104^M 104 {}^M (gdb) PASS: gdb.base/linux-kernel.exp: continue to breakpoint: stop at this point, the list of tasks are set up, switch to linux-kernel target layer, target linux-kernel^M [New process 8001]^M (gdb) PASS: gdb.base/linux-kernel.exp: target linux-kernel maintenance print target-stack^M The current target stack is:^M - linux-kernel (linux kernel support)^M - native (Native process)^M - exec (Local exec file)^M - None (None)^M It works! In this way, we can test that GDB can successfully parse the these data structures in Linux kernel without Linux kernel image at all. Then, we can generate a coredump, (gdb) generate-core-file=20 Saved corefile core.9614 Remove the hack in lk_observer_inferior_created, so that GDB can automatically push linux-kernel target layer, $ ./gdb ./testsuite/outputs/gdb.base/linux-kernel/linux-kernel ./core.9614 [New LWP 9614] [New process 9614] Core was generated by `/scratch/yao/gdb/build-git/x86_64/gdb/testsuite/outp= uts/gdb.base/linux-kernel/li'. Program terminated with signal SIGTRAP, Trace/breakpoint trap. #0 stop () at /home/yao/SourceCode/gnu/gdb/git/gdb/testsuite/gdb.base/linu= x-kernel.c:104 104 {} [Current thread is 1 (PID: 9614*, 0x602010)] (gdb) maintenance print target-stack=20 The current target stack is: - linux-kernel (linux kernel support) - core (Local core dump file) - exec (Local exec file) - None (None) The next step would be extending the test case to a multi-threaded program, so that we can create task lists for these threads, and generate coredump which is similar to the kernel coredump. --=20 Yao (=E9=BD=90=E5=B0=A7) #include #include #include static char linux_banner[10]; static int _stext =3D 0; static int _etext =3D 0; typedef int pid_t; struct list_head { struct list_head *next, *prev; }; #define LIST_HEAD_INIT(name) (struct list_head) { &(name), &(name) } struct thread_struct {}; struct task_struct { struct list_head tasks; pid_t pid; pid_t tgid; struct list_head thread_group; char comm[20]; struct thread_struct thread; }; struct rq { struct task_struct *curr; }; #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) #define BITS_PER_BYTE 8 #define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof (lo= ng)) #define DECLARE_BITMAP(name,bits) \ unsigned long name[BITS_TO_LONGS(bits)] #define NR_CPUS 10 struct cpumask { DECLARE_BITMAP(bits, NR_CPUS); }; struct cpumask __cpu_online_mask; static void cpumask_set_cpu (unsigned int cpu, struct cpumask* dstp) { dstp->bits[cpu / (BITS_PER_BYTE * sizeof (long))] |=3D 1UL << (cpu % (BITS_PER_BYTE * sizeof (long))); } struct task_struct init_task;; struct rq runqueues[NR_CPUS]; struct cpumask baz; unsigned long __per_cpu_offset[NR_CPUS]; struct mm_struct {}; struct mm_struct init_mm; static void setup (void) { int i; struct task_struct *task; /* Set up __per_cpu_offset. */ for (i =3D 0; i < NR_CPUS; i++) __per_cpu_offset[i] =3D i * sizeof (runqueues[0]); /* Mark cpu 0 is online. */ cpumask_set_cpu (0, &__cpu_online_mask); init_task.tasks =3D LIST_HEAD_INIT(init_task.tasks); init_task.thread_group =3D LIST_HEAD_INIT(init_task.thread_group); task =3D malloc (sizeof (struct task_struct)); memset (task, 0, sizeof (sizeof (struct task_struct))); task->pid =3D getpid (); runqueues[0].curr =3D task; /* Chain it tasks list. */ init_task.tasks.next =3D (struct list_head *) task; init_task.tasks.prev =3D (struct list_head *) task; task->tasks.next =3D (struct list_head *) &init_task; task->tasks.prev =3D (struct list_head *) &init_task; /* TASK is the group leader. */ task->thread_group =3D LIST_HEAD_INIT(task->thread_group); } static void stop (void) {} int main (void) { setup (); stop (); return 0; }