From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1p8w1E-0002nU-GP for mharc-grub-devel@gnu.org; Fri, 23 Dec 2022 23:20:20 -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 1p8w16-0002mK-53 for grub-devel@gnu.org; Fri, 23 Dec 2022 23:20:12 -0500 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p8w14-0000X3-4U for grub-devel@gnu.org; Fri, 23 Dec 2022 23:20:11 -0500 Received: by mail-pj1-x102c.google.com with SMTP id ge16so2865325pjb.5 for ; Fri, 23 Dec 2022 20:20:09 -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=VYSQ2KYm2gLaLZpXQ9gKJkQxS9KRrpilBhZ3SA12gFs=; b=gIBPCQzFR7NZW8r+kW4fsPCtGJwQM5ykCiI1Q0CbyjFnH7XYgo0NXwamd6SiX8Jmng c1euogDDwCT1awJpzoOHnhueO3fc1uKDBD4Z3qGubJCNFa7hWyGrue4xqiX7Ox+SUL1B ufVWarQuqWprrlw3rS+OoBHmiAZRGqMjoZgrMyzs0ph4hCycA+T+wtVENJfJ33g3znrS zfYewZiYT5QSLcZr2xx7G/wEDzwmNaRBb7PLhAARihkVQKsMF9opnBUXcYBjC1l+2TM2 OiYxbUdrigq7VLrfNsZwQQC5HT8NZIEufw5VtnroG1DvQYSlNNHcb3JrMeGiWA3JNp0J IotA== 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=VYSQ2KYm2gLaLZpXQ9gKJkQxS9KRrpilBhZ3SA12gFs=; b=Hni4G13dDkJ0eDaP3ueJ2prte2vN7+pSXkdMVvJ7ibsTwGYCLer6148DBAab3OshV0 e1OnOj16kKLV4URcJMCGVxeXntzmYor+n9B03EmcHCBpRT5pS/KH0KguZj7V0bAHD5Q9 WfiVQmP2R2AId7+gsAs/Q+S8TicAxUHckah1GLT1pUk1Lf0TwbSWLsr9t3CScOkIVoIw hnG3WyvdpR0pOSgw+MAfIySbnfhBys24PQ5QT8I71njmA6lIPoZ7dqabmv2YdffpSVps 2AUmEdtHIU5VbGcEfP4pE+YHD5zjBEJdzRGnhYBHwwNNrBsV5v+ZEwV6yQp6G/ygTDin 2ocg== X-Gm-Message-State: AFqh2kpe6RumCnpDmHON77uhjNSdecgVdj3vINEGsKyZ6W+k7YztLtqY d3uqf/3Fzbh4Cs3wT0rAHC9DwBzzkXFK2puI X-Google-Smtp-Source: AMrXdXurEXMwVKweFLcMDNnmN0YUrXs1ouO04ve6oUGD7atYWHt+qYt7VjizqxfZfbKD4OyCXZUrwQ== X-Received: by 2002:a05:6a21:3d0d:b0:a3:8d47:6aa9 with SMTP id bi13-20020a056a213d0d00b000a38d476aa9mr16361564pzc.34.1671855608342; Fri, 23 Dec 2022 20:20:08 -0800 (PST) Received: from localhost.localdomain ([204.13.164.84]) by smtp.gmail.com with ESMTPSA id x19-20020aa79413000000b005743b5ebd7csm3324185pfo.92.2022.12.23.20.20.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Dec 2022 20:20:07 -0800 (PST) From: Glenn Washburn To: grub-devel@gnu.org, Daniel Kiper Cc: Robbie Harwood , Peter Jones , Glenn Washburn Subject: [PATCH v5 05/14] gdb: Conditionally run GDB script logic for dynamically or statically positioned GRUB Date: Fri, 23 Dec 2022 22:19:26 -0600 Message-Id: <20221224041935.787292-6-development@efficientek.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221224041935.787292-1-development@efficientek.com> References: <20221224041935.787292-1-development@efficientek.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=development@efficientek.com; helo=mail-pj1-x102c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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: Sat, 24 Dec 2022 04:20:12 -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 d525a5a11f..620d1def72 100644 --- a/grub-core/gdb_grub.in +++ b/grub-core/gdb_grub.in @@ -86,7 +86,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