From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1pFMWb-0004hL-Uo for mharc-grub-devel@gnu.org; Tue, 10 Jan 2023 16:51:17 -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 1pFMWa-0004ez-Ci for grub-devel@gnu.org; Tue, 10 Jan 2023 16:51:16 -0500 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pFMWY-0002Mc-QW for grub-devel@gnu.org; Tue, 10 Jan 2023 16:51:16 -0500 Received: by mail-pl1-x62b.google.com with SMTP id b17so7149362pld.7 for ; Tue, 10 Jan 2023 13:51:14 -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=4F2XIRG7zUlzZa6vlhP5JUL7YkE8BynuFXoXfK+mP9m/2DBYTqdRu6IKhfWtxknisx 82HD0C9MaKfVtciKET+YZ7Wb0TMXt8/s90ARz9wxNkU/AAdZ89rewHb0FXAESYtPOejK eEyMcD5I/dbWobqRZhnYR65p116oEPBQ8X5ljcHgjeNSSm3Nxm3c2j4dZDY/xxW/1p8u 9faUa+lY6fniQdhvG/eDZ4OItQ4LbXdv2rwg5mPBlMz20JL93g/1ckpD+7V10C5XgnTS uUn1FETsLykAeE/8DBYQrCrcAm9Eigny9zxPPfbTh0V5Mx5cOZQNp8qMgEvoCAaoLOML J0mA== 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=BNCWRxfcxutJUVUOrszfTOPPY8eoUGdNf53R+MoEaJq/5gxX9tc4PmqzbI+Ww11t6P e+DONQb3ZMvzj/puGrzdzv8RHumGSu0gPeiWFGzoBV7EHD2b6AtfYrLnyiv8yqtE14tQ nqixf74pwSll5Ts057EUP7+NGf9DO3slqtCVSX3OHE7gbLYpbyH5uskvcIoElWriIeMJ NEs86eRfH7PGwfrZHpj/noj5kXPHW6+nw9vpsoZsJ5BMnTcjg7Jh3p/YZyJvcuCgThx6 li72KO3o4xADrG1cUojQ1bLHiQl1AQ56xVh64t3IOqHpm8NvKGlzip8RfxvIW2WDDtS3 arKg== X-Gm-Message-State: AFqh2krPzp6+wEa46+9F6DjsNqxGOEEqLYF0VOL0HNb+NeM4KJWkOGIA i07sp68eBMf+nsQrbNgZ3KMVN/yAV763n8Hb X-Google-Smtp-Source: AMrXdXs0O4/T/iESC0e/j2HMGfSNEBP0FgXUrInrvuD8g870H2T5V0kN+N1Je8KnzJwubGe5uvBDuA== X-Received: by 2002:a17:903:330b:b0:193:30be:d146 with SMTP id jk11-20020a170903330b00b0019330bed146mr8386582plb.63.1673387473021; Tue, 10 Jan 2023 13:51:13 -0800 (PST) Received: from crass-HP-ZBook-15-G2.lan ([199.254.238.56]) by smtp.gmail.com with ESMTPSA id u15-20020a1709026e0f00b00186c3af9644sm7760798plk.273.2023.01.10.13.51.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Jan 2023 13:51:12 -0800 (PST) From: Glenn Washburn To: grub-devel@gnu.org, Daniel Kiper Cc: Robbie Harwood , Peter Jones , Glenn Washburn Subject: [PATCH v6 05/14] gdb: Conditionally run GDB script logic for dynamically or statically positioned GRUB Date: Tue, 10 Jan 2023 15:50:32 -0600 Message-Id: <20230110215041.1247699-6-development@efficientek.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230110215041.1247699-1-development@efficientek.com> References: <20230110215041.1247699-1-development@efficientek.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=development@efficientek.com; helo=mail-pl1-x62b.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: Tue, 10 Jan 2023 21:51:16 -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