From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 8LyWNDHU9l8mBAAAWB0awg (envelope-from ) for ; Thu, 07 Jan 2021 04:28:17 -0500 Received: by simark.ca (Postfix, from userid 112) id D37FC1E965; Thu, 7 Jan 2021 04:28:17 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id BFCFA1E590 for ; Thu, 7 Jan 2021 04:28:16 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 88799395C047; Thu, 7 Jan 2021 09:28:16 +0000 (GMT) Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id 5B36F394D8BE for ; Thu, 7 Jan 2021 09:28:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5B36F394D8BE Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=andrew.burgess@embecosm.com Received: by mail-wr1-x429.google.com with SMTP id c5so4915872wrp.6 for ; Thu, 07 Jan 2021 01:28:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=hFSs4QbUGPEP65dnDcy1NWFuZRQyDis4DpfhNCi0ri0=; b=HqBvHvY2Vx88fLy4BVnyc2fb0uY1HQNZjY9CO+m+adYr8KSfijNFucsvNLLQ+qGii1 heBgpYIrYeEqrizZuYUGX1x24YJ7xl5R5Rp/B0U+maUCL+sBT8aZdIdJ0sn9XA2+Ttjb WN3gkDyhu1uNgutokOH7Q3P9i60/D9N9un5dXKpvkyB5tP/+oMmexy59ixAmKx4st/Gw ecruiszqXSveTztsPmQnzz7V40XSzRl0lHEP1Q4/lbFfLn7kHaOwbzESD8UJDYLtQuHL /S47JdTv5e7JSaBx2VMuTg8lQzA58iKvQzpRJnokPI1EYKXMiGqJRu5lJDi10nu7z/aF lQnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=hFSs4QbUGPEP65dnDcy1NWFuZRQyDis4DpfhNCi0ri0=; b=fKuVZjEETl8ATF9P4AI/l9B+XLDcNZJse5HggP4e+BW8LYrKLJDi/UWCWyp2l363yK ucw5DbTm+VB9LcFjOBQGEhY8xBW6VM4dxMC+1vs1HZrIQIits9dJDgQ807HRqpmAQ0CS dbS2GCd+0ejt7ulblJ0UK9EhsTvODqkX2th5YlZ9vC5MOddZX1WQMjcSk3g4D96yKJhP wbTeTU3l7v96COM2dAIVskWf4xJzQeLgmqweO+JGsFCQCtU+IEMK5toUGWOP2MciHOTa M5PMm5RSwrYJ6uPigbnLyJnIlyEwYVzoyY00jAd37qWGwCMwcNET/2gMRI6IUMJEjkIZ nAXA== X-Gm-Message-State: AOAM531yT9Qoq9HFoNH7J1INIUiDaD+Ow6KSrYV/Y/kGTpGWD9wfWIDd /5JeUtbTDMlwu0+LcamNqRTxU/XunYtT0w== X-Google-Smtp-Source: ABdhPJwb/Rhj65/M5VduJJ1vCD6YzVzrqif5BQybZ711Im8647LCEKK2PhpA9S8RTAFwtmXwAqAYog== X-Received: by 2002:adf:e410:: with SMTP id g16mr8076606wrm.364.1610011692412; Thu, 07 Jan 2021 01:28:12 -0800 (PST) Received: from localhost (host86-166-129-230.range86-166.btcentralplus.com. [86.166.129.230]) by smtp.gmail.com with ESMTPSA id r7sm6442518wmh.2.2021.01.07.01.28.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jan 2021 01:28:11 -0800 (PST) Date: Thu, 7 Jan 2021 09:28:11 +0000 From: Andrew Burgess To: Mike Frysinger Subject: Re: [PATCH v2] gdb/sim: add support for exporting memory map Message-ID: <20210107092811.GK2945@embecosm.com> References: <20210106060433.12043-1-vapier@gentoo.org> <20210106110430.23136-1-vapier@gentoo.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210106110430.23136-1-vapier@gentoo.org> X-Operating-System: Linux/5.8.13-100.fc31.x86_64 (x86_64) X-Uptime: 09:28:01 up 29 days, 14:12, X-Editor: GNU Emacs [ http://www.gnu.org/software/emacs ] X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: gdb-patches@sourceware.org Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" * Mike Frysinger via Gdb-patches [2021-01-06 06:04:30 -0500]: > This allows gdb to quickly dump & process the memory map that the sim > knows about. This isn't fully accurate, but is largely limited by the > gdb memory map format. While the sim supports RWX bits, gdb can only > handle RW or RO regions. > --- > gdb/remote-sim.c | 18 +++++++++++++ > include/gdb/remote-sim.h | 9 +++++++ > sim/common/sim-core.c | 57 ++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 84 insertions(+) LGTM. Thanks, Andrew > > diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c > index c4f3913edbad..b21a4e80ee6a 100644 > --- a/gdb/remote-sim.c > +++ b/gdb/remote-sim.c > @@ -42,6 +42,7 @@ > #include "readline/readline.h" > #include "gdbthread.h" > #include "gdbsupport/byte-vector.h" > +#include "memory-map.h" > > /* Prototypes */ > > @@ -164,6 +165,7 @@ struct gdbsim_target final > > bool has_all_memory () override; > bool has_memory () override; > + std::vector memory_map () override; > > private: > sim_inferior_data *get_inferior_data_by_ptid (ptid_t ptid, > @@ -1270,6 +1272,22 @@ gdbsim_target::has_memory () > return true; > } > > +/* Get memory map from the simulator. */ > + > +std::vector > +gdbsim_target::memory_map () > +{ > + struct sim_inferior_data *sim_data > + = get_sim_inferior_data (current_inferior (), SIM_INSTANCE_NEEDED); > + std::vector result; > + gdb::unique_xmalloc_ptr text (sim_memory_map (sim_data->gdbsim_desc)); > + > + if (text != nullptr) > + result = parse_memory_map (text.get ()); > + > + return result; > +} > + > void _initialize_remote_sim (); > void > _initialize_remote_sim () > diff --git a/include/gdb/remote-sim.h b/include/gdb/remote-sim.h > index 73fb670c17e5..a3ba3aa36cd2 100644 > --- a/include/gdb/remote-sim.h > +++ b/include/gdb/remote-sim.h > @@ -213,6 +213,15 @@ int sim_store_register (SIM_DESC sd, int regno, unsigned char *buf, int length); > void sim_info (SIM_DESC sd, int verbose); > > > +/* Return a memory map in XML format. > + > + The caller must free the returned string. > + > + For details on the format, see GDB's Memory Map Format documentation. */ > + > +char *sim_memory_map (SIM_DESC sd); > + > + > /* Run (or resume) the simulated program. > > STEP, when non-zero indicates that only a single simulator cycle > diff --git a/sim/common/sim-core.c b/sim/common/sim-core.c > index 74369aa99fe2..538230635bc9 100644 > --- a/sim/common/sim-core.c > +++ b/sim/common/sim-core.c > @@ -452,6 +452,63 @@ sim_core_translate (sim_core_mapping *mapping, > } > > > +#if EXTERN_SIM_CORE_P > +/* See include/gdb/remote-sim.h. */ > +char * > +sim_memory_map (SIM_DESC sd) > +{ > + sim_core *core = STATE_CORE (sd); > + unsigned map; > + char *s1, *s2, *entry; > + > + s1 = xstrdup ( > + "\n" > + " + " 'http://sourceware.org/gdb/gdb-memory-map.dtd'>\n" > + "\n"); > + > + for (map = 0; map < nr_maps; ++map) > + { > + sim_core_mapping *mapping; > + > + for (mapping = core->common.map[map].first; > + mapping != NULL; > + mapping = mapping->next) > + { > + /* GDB can only handle a single address space. */ > + if (mapping->level != 0) > + continue; > + > + entry = xasprintf ("\n", > + mapping->base, mapping->nr_bytes); > + /* The sim memory map is organized by access, not by addresses. > + So a RWX memory map will have three independent mappings. > + GDB's format cannot support overlapping regions, so we have > + to filter those out. > + > + Further, GDB can only handle RX ("rom") or RWX ("ram") mappings. > + We just emit "ram" everywhere to keep it simple. If GDB ever > + gains support for more stuff, we can expand this. > + > + Using strstr is kind of hacky, but as long as the map is not huge > + (we're talking <10K), should be fine. */ > + if (strstr (s1, entry) == NULL) > + { > + s2 = concat (s1, entry, NULL); > + free (s1); > + s1 = s2; > + } > + free (entry); > + } > + } > + > + s2 = concat (s1, "", NULL); > + free (s1); > + return s2; > +} > +#endif > + > + > #if EXTERN_SIM_CORE_P > unsigned > sim_core_read_buffer (SIM_DESC sd, > -- > 2.28.0 >