From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 89574 invoked by alias); 2 May 2017 11:14:48 -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 89556 invoked by uid 89); 2 May 2017 11:14:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=BAYES_00,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=ham version=3.3.2 spammy=beneath, silent, 4.5, secondly X-HELO: mail-wm0-f65.google.com Received: from mail-wm0-f65.google.com (HELO mail-wm0-f65.google.com) (74.125.82.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 02 May 2017 11:14:45 +0000 Received: by mail-wm0-f65.google.com with SMTP id y10so3535482wmh.0 for ; Tue, 02 May 2017 04:14:47 -0700 (PDT) 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=2mKiILfUQ5fXV4gJTNnu+g0LHqBEiiRfs+sMOoER/M0=; b=aEi3BI/jtpvrqq8tEMnDtuswVExWyCA7SM9Cj0ZTaWUoPmq1w/mQs42sAiQIsgAJIX fC2UlLXFSe9Um9Lt1QymhYCa8vNphGS3HnaOi5VDVhm6EiBcHA0VAvOFk8EQbbCE582d 8z94OLTh2BzAHmew5i3K4yZSxkBKfjbP2HPPygQrH4Gqb4YzqaBWAdtwKmqp68jpSwGy DpORsFpR7B7h3yViyFyBnkiXT5TtLcY9A5tMuZ21uDUQYiGhL1Lblh2B0JYn/Wxbt/AT NcCqqgYmtAMuyo6XWKmLcJuhhksCCTPCAXk7ygrBaQpNvMsC5IvvN0oOpJplPn1MzUIu 19Yw== X-Gm-Message-State: AN3rC/477o8w2vKt0KPjga0BruTop8tiLnuaD14t5WzfE94wrK75sVoW iokaUHEle4K9BQ== X-Received: by 10.28.199.2 with SMTP id x2mr1845045wmf.94.1493723685441; Tue, 02 May 2017 04:14:45 -0700 (PDT) Received: from E107787-LIN ([194.214.185.158]) by smtp.gmail.com with ESMTPSA id t124sm620240wma.10.2017.05.02.04.14.44 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 02 May 2017 04:14:44 -0700 (PDT) From: Yao Qi To: Philipp Rudo Cc: gdb-patches@sourceware.org, Yao Qi , Peter Griffin , Omair Javaid , Andreas Arnez Subject: Re: [RFC v3 3/8] Add basic Linux kernel support References: <20170316165739.88524-1-prudo@linux.vnet.ibm.com> <20170316165739.88524-4-prudo@linux.vnet.ibm.com> Date: Tue, 02 May 2017 11:14:00 -0000 In-Reply-To: <20170316165739.88524-4-prudo@linux.vnet.ibm.com> (Philipp Rudo's message of "Thu, 16 Mar 2017 17:57:34 +0100") Message-ID: <86d1br8q8v.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-05/txt/msg00004.txt.bz2 Philipp Rudo writes: Hi Philipp, > +/* Initialize architecture independent private data. Must be called > + _after_ symbol tables were initialized. */ > + > +static void > +lk_init_private_data () > +{ > + if (LK_PRIVATE->data !=3D NULL) > + htab_empty (LK_PRIVATE->data); > + > + LK_DECLARE_FIELD (task_struct, tasks); > + LK_DECLARE_FIELD (task_struct, pid); > + LK_DECLARE_FIELD (task_struct, tgid); > + LK_DECLARE_FIELD (task_struct, thread_group); > + LK_DECLARE_FIELD (task_struct, comm); > + LK_DECLARE_FIELD (task_struct, thread); > + > + LK_DECLARE_FIELD (list_head, next); > + LK_DECLARE_FIELD (list_head, prev); > + > + LK_DECLARE_FIELD (rq, curr); > + > + LK_DECLARE_FIELD (cpumask, bits); > + > + LK_DECLARE_ADDR (init_task); > + LK_DECLARE_ADDR (runqueues); > + LK_DECLARE_ADDR (__per_cpu_offset); > + LK_DECLARE_ADDR (init_mm); > + > + LK_DECLARE_ADDR_ALIAS (__cpu_online_mask, cpu_online_mask); /* linux 4= .5+ */ > + LK_DECLARE_ADDR_ALIAS (cpu_online_bits, cpu_online_mask); /* linux -4.= 4 */ > + if (LK_ADDR (cpu_online_mask) =3D=3D -1) > + error (_("Could not find address cpu_online_mask. Aborting.")); > +} > + > + > +/* Initialize linux kernel target. */ > + > +static void > +init_linux_kernel_ops (void) > +{ > + struct target_ops *t; > + > + if (linux_kernel_ops !=3D NULL) > + return; > + > + t =3D XCNEW (struct target_ops); > + t->to_shortname =3D "linux-kernel"; > + t->to_longname =3D "linux kernel support"; > + t->to_doc =3D "Adds support to debug the Linux kernel"; > + > + /* set t->to_data =3D struct lk_private in lk_init_private. */ > + > + t->to_open =3D lk_open; > + t->to_close =3D lk_close; > + t->to_detach =3D lk_detach; > + t->to_fetch_registers =3D lk_fetch_registers; > + t->to_update_thread_list =3D lk_update_thread_list; > + t->to_pid_to_str =3D lk_pid_to_str; > + t->to_thread_name =3D lk_thread_name; > + > + t->to_stratum =3D thread_stratum; > + t->to_magic =3D OPS_MAGIC; > + > + linux_kernel_ops =3D t; > + > + add_target (t); > +} > + > +/* Provide a prototype to silence -Wmissing-prototypes. */ > +extern initialize_file_ftype _initialize_linux_kernel; > + > +void > +_initialize_linux_kernel (void) > +{ > + init_linux_kernel_ops (); > + > + observer_attach_new_objfile (lk_observer_new_objfile); > + observer_attach_inferior_created (lk_observer_inferior_created); > +} > diff --git a/gdb/lk-low.h b/gdb/lk-low.h > new file mode 100644 > index 0000000..292ef97 > --- /dev/null > +++ b/gdb/lk-low.h > @@ -0,0 +1,310 @@ > +/* Basic Linux kernel support, architecture independent. > + > + Copyright (C) 2016 Free Software Foundation, Inc. > + > + This file is part of GDB. > + > + This program is free software; you can redistribute it and/or modify > + it under the terms of the GNU General Public License as published by > + the Free Software Foundation; either version 3 of the License, or > + (at your option) any later version. > + > + This program is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + GNU General Public License for more details. > + > + You should have received a copy of the GNU General Public License > + along with this program. If not, see .= */ > + > +#ifndef __LK_LOW_H__ > +#define __LK_LOW_H__ > + > +#include "target.h" > + > +extern struct target_ops *linux_kernel_ops; > + > +/* Copy constants defined in Linux kernel. */ > +#define LK_TASK_COMM_LEN 16 > +#define LK_BITS_PER_BYTE 8 > + > +/* Definitions used in linux kernel target. */ > +#define LK_CPU_INVAL -1U > + > +/* Private data structs for this target. */ > +/* Forward declarations. */ > +struct lk_private_hooks; > +struct lk_ptid_map; > + > +/* Short hand access to private data. */ > +#define LK_PRIVATE ((struct lk_private *) linux_kernel_ops->to_data) > +#define LK_HOOK (LK_PRIVATE->hooks) > + > +struct lk_private "private" here is a little confusing. How about rename it to "linux_kernel= "? > +{ > + /* Hashtab for needed addresses, structs and fields. */ > + htab_t data; > + > + /* Linked list to map between cpu number and original ptid from target > + beneath. */ > + struct lk_ptid_map *old_ptid; > + > + /* Hooks for architecture dependent functions. */ > + struct lk_private_hooks *hooks; > +}; > + Secondly, can we change it to a class and function pointers in lk_private_hooks become virtual functions. gdbarch_lk_init_private returns a pointer to an instance of sub-class of "linux_kernel". lk_init_private_data can be put the constructor of base class, to add entries to "data", and sub-class (in each gdbarch) can add their own specific stuff. > + > +/* Functions to initialize private data. Do not use directly, use the > + macros below instead. */ > + > +extern struct lk_private_data *lk_init_addr (const char *name, > + const char *alias, int silent); > +extern struct lk_private_data *lk_init_struct (const char *name, > + const char *alias, int silent); > + > +/* Definitions for architecture dependent hooks. */ > +/* Hook to read registers from the target and supply their content > + to the regcache. */ > +typedef void (*lk_hook_get_registers) (CORE_ADDR task, > + struct target_ops *target, > + struct regcache *regcache, > + int regnum); > + > +/* Hook to return the per_cpu_offset of cpu CPU. Only architectures that > + do not use the __per_cpu_offset array to determin the offset have to > + supply this hook. */ > +typedef CORE_ADDR (*lk_hook_get_percpu_offset) (unsigned int cpu); > + > +/* Hook to map a running task to a logical CPU. Required if the target > + beneath uses a different PID as struct rq. */ > +typedef unsigned int (*lk_hook_map_running_task_to_cpu) (struct thread_i= nfo *ti); > + > +struct lk_private_hooks > +{ > + /* required */ > + lk_hook_get_registers get_registers; > + > + /* optional, required if __per_cpu_offset array is not used to determi= ne > + offset. */ > + lk_hook_get_percpu_offset get_percpu_offset; > + > + /* optional, required if the target beneath uses a different PID as st= ruct > + rq. */ > + lk_hook_map_running_task_to_cpu map_running_task_to_cpu; > +}; --=20 Yao (=E9=BD=90=E5=B0=A7)