Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1pWkqw-0007PK-0C for mharc-grub-devel@gnu.org; Mon, 27 Feb 2023 16:16:10 -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 1pWkqv-0007MD-3M for grub-devel@gnu.org; Mon, 27 Feb 2023 16:16:09 -0500 Received: from mail-qt1-x82b.google.com ([2607:f8b0:4864:20::82b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pWkqt-0000Mc-13 for grub-devel@gnu.org; Mon, 27 Feb 2023 16:16:08 -0500 Received: by mail-qt1-x82b.google.com with SMTP id cf14so8276750qtb.10 for ; Mon, 27 Feb 2023 13:16:06 -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=ibPqU2jrqUXoLrVR+BhFOzHXPibPW1m7WWYbtEED6r8=; b=OzrEsORNnqOZ+VHfO6Pswy0/VWEeQumHfMW3j8OZCPF4sR1H/ax51shQzCRnz3xwio J/Qw9WN6eTEFLa6mTRkfubFrZaN+Cavoz51DoLgrSGhsvYKdlAi3cEVNOQdd5bpmUoLz 7KXNP+NuNPitVKzNA4sGMaGlnozYSxNypvjdBV7s+iP/Ae+7nhcn5hBkNaFXZNd07Ws+ COZFm462VoC7jw/7w/23mUIP7ViuiIxlP2hxs15HxH7O+bj4FqtJYSHn738IJlH9vl2k cCZRCMwfBscn9Wy/9tp72/tjCD6iwA4hiCQqfWMeKRRy2me/nenAtMenNchhh9Ufb/TZ fjWQ== 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=ibPqU2jrqUXoLrVR+BhFOzHXPibPW1m7WWYbtEED6r8=; b=HWxRV5W2AHf/jTPlweUhXta/PYlORd9ly0HXShR0a4+ILBMjdG1i4pM9QgINXp8UWy rAkkibzfRL2uQtD17cv9l+f961dTyn6B8GR9zdheM4OLGYijExOQ5eb6Os0Npdyl2mUt I1asA+zlhA48fjyxSwZBCND81mcKcf+/+6hFMuG32wdAUadjeKA7YRZ6BPwbiYBXNcto tGvl17zOeWAz2JlyArxdbcO6Yk9dxDFW2iG7Jy0ezBlbA/o/rfG1K8wJ2oF1ZHBRhMnN pE2nfC+n39YrAzIc+BuDBzYI7HqR2LOfBzyzf/eIysrbSybXF/Z2OHgDQGJ1RZHgD5aT aFgA== X-Gm-Message-State: AO0yUKV51GEMoYWE06qCbkihKK+O//SJU3Ws16dnIyJ71h8iQSicZ3vN NgQsrrylMnjgMrKhXykL7aJpsO5pKyTZ0uU3 X-Google-Smtp-Source: AK7set8GgcuzBbGITJbH4r7g6ZinIHYrHWRXT4/1klHxX5Tx+/Af+DLrvtf2XYvMMYIXgCis423lfQ== X-Received: by 2002:a05:622a:1902:b0:3b9:bc8c:c1f9 with SMTP id w2-20020a05622a190200b003b9bc8cc1f9mr18964344qtc.4.1677532565536; Mon, 27 Feb 2023 13:16:05 -0800 (PST) Received: from localhost.localdomain ([37.218.244.251]) by smtp.gmail.com with ESMTPSA id n76-20020a37404f000000b0071aacb2c76asm5475080qka.132.2023.02.27.13.16.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Feb 2023 13:16:04 -0800 (PST) From: Glenn Washburn To: grub-devel@gnu.org, Daniel Kiper Cc: Glenn Washburn Subject: [PATCH 2/8] gdb: Conditionally run GDB script logic for dynamically or statically positioned GRUB Date: Mon, 27 Feb 2023 15:15:32 -0600 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::82b; envelope-from=development@efficientek.com; helo=mail-qt1-x82b.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: Mon, 27 Feb 2023 21:16:09 -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 d525a5a11f01..620d1def72d0 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