From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1p5iNQ-0007Vu-AS for mharc-grub-devel@gnu.org; Thu, 15 Dec 2022 02:09:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p5iNO-0007Vc-M7 for grub-devel@gnu.org; Thu, 15 Dec 2022 02:09:54 -0500 Received: from mail-qt1-x82e.google.com ([2607:f8b0:4864:20::82e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p5iNN-00081l-5V for grub-devel@gnu.org; Thu, 15 Dec 2022 02:09:54 -0500 Received: by mail-qt1-x82e.google.com with SMTP id c7so4484950qtw.8 for ; Wed, 14 Dec 2022 23:09:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=I23so83iicBOf4Z84e6nrkifAvvYbRGuDdGvSiM7TNw=; b=ZH2mOM37MRdH7nubkBGWkeXv7OYfEaJkrpExVNqCUjdbi7z1dbhdf94R3caf2Jv884 54foyW1hxIv0iFm5qpbpbhGbsPYRVlnSaN3tjSn0uodYqxTnqjUzyiVmdTvWEPu9HLQt +W1yjKIoC+oRvTnoHlCWqbINRNAQ1xReSRvi2j543XfLS9t9NqhSM2NEw8cM/JM/bQh4 KzMKytBcYbKQ8ZtOgd/7y5RQX7igOm3AVStaZPyY2fbISCpwictSa+LS8sV8vW4f1+7z DNOgwUIYrd2Gx+NDVHA1uO5ryFW6s8e57vDzN2lzbOxPVJfQDCScgFUf09XgwrwPG8lS n+6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=I23so83iicBOf4Z84e6nrkifAvvYbRGuDdGvSiM7TNw=; b=gxPnMcywbPTdq8bDJryTgHHLC/ejmW2iIwYtVUHWQt6sIMEa1azijqAPoxG8TzGRME zE+SI2qT4G7H6d7YvAbvnD1z/swvanN4KwuCEnim5x/B/xoiikUmagv5Svig12C1TRgk xedAR8I/g98S2n8QVX341qJ3mctbE2JL8GldhuZu0k3jBWFdjoS/NWHK+lEF7onfYtOI jP+o+Y5SuhJsxA2A0PELeYIni1w3gZjV5ul9Q9Gj/jXOTv9wpBytpfJRSgzRtQCZTndN 6AmxyeH1+pme6JvA7Z+kONFaAvSA3G0NHvTeQLMubzBn42QJrUv4G6RQ8pd2Tg4sFsx2 F52w== X-Gm-Message-State: ANoB5pnfsGETzHYMFlI0MVpUf5qKkDhO2pvAYPe0vPkMNWnhaHvMCANo PHStjvF8BEJHFOscVJ4jwt7OK4cDcnbqLLfQ X-Google-Smtp-Source: AA0mqf78MVi05bHGY2xh15urmpsrt8Lz7CiEWRhJzrjSF+4C+MstjHg6tCVG0G+VJlfZowJkjXdxdA== X-Received: by 2002:a05:622a:90c:b0:3a5:3134:48ac with SMTP id bx12-20020a05622a090c00b003a5313448acmr16202793qtb.3.1671088192130; Wed, 14 Dec 2022 23:09:52 -0800 (PST) Received: from crass-HP-ZBook-15-G2.lan ([37.218.244.251]) by smtp.gmail.com with ESMTPSA id fy16-20020a05622a5a1000b003a7ec97c882sm3125068qtb.6.2022.12.14.23.09.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Dec 2022 23:09:51 -0800 (PST) From: Glenn Washburn To: grub-devel@gnu.org, Daniel Kiper Cc: Glenn Washburn Subject: [PATCH v3 10/15] gdb: Conditionally run GDB script logic for dynamically or statically positioned GRUB Date: Thu, 15 Dec 2022 01:07:45 -0600 Message-Id: <20221215070750.102591-11-development@efficientek.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221215070750.102591-1-development@efficientek.com> References: <20221215070750.102591-1-development@efficientek.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::82e; envelope-from=development@efficientek.com; helo=mail-qt1-x82e.google.com X-Spam_score_int: 14 X-Spam_score: 1.4 X-Spam_bar: + X-Spam_report: (1.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Dec 2022 07:09:54 -0000 There are broadly two classes of targets to consider when loading symbols for GRUB, targets that determine where to load GRUB at runtime (dynamically positioned) and those that do not (statically positioned). For statically poisitioned targets, symbol loading is determined at link time, so nothing more needs to be known to load the symbols. For dynamically positioned targets, such as EFI targets, at runtime symbols should be offset by an amount that depends on where the runtime chose to load GRUB. It is important to not load symbols statically for dynamic targets because then when subsequently loading the symbols correctly one must take care to remove the existing static symbols, otherwise there will be two sets of symbols and GDB seems to prefer the ones loaded first (ie the static ones). Use autoconf variables to generate a gdb_grub for a particular target, which conditionally run startup code depending on if the target uses static or dynamic loading. Signed-off-by: Glenn Washburn --- grub-core/gdb_grub.in | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/grub-core/gdb_grub.in b/grub-core/gdb_grub.in index eb4f7041bc..a444000ff0 100644 --- a/grub-core/gdb_grub.in +++ b/grub-core/gdb_grub.in @@ -149,7 +149,20 @@ end ### set confirm off -file kernel.exec -target remote :1234 -runtime_load_module +# Note: On EFI and other platforms that load GRUB to an address that is +# determined at runtime, the symbols in kernel.exec will be wrong. +# However, we must start by loading some executable file or GDB will +# fail. + +set $platform_efi = $_streq("@platform@", "efi") + +if $platform_efi + # Only load the executable file, not the symbols + exec-file kernel.exec +else + file kernel.exec + runtime_load_module +end + +target remote :1234 -- 2.34.1