From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1p63J6-0003w4-MX for mharc-grub-devel@gnu.org; Fri, 16 Dec 2022 00:30:52 -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 1p63J4-0003uE-7O for grub-devel@gnu.org; Fri, 16 Dec 2022 00:30:50 -0500 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p63J2-00048y-NA for grub-devel@gnu.org; Fri, 16 Dec 2022 00:30:49 -0500 Received: by mail-pl1-x629.google.com with SMTP id s7so1271846plk.5 for ; Thu, 15 Dec 2022 21:30:48 -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=J03UqeBP8rNnazFggPBxtMyPdkfsUcFaI+RcGcDWfVs=; b=d+dHZngA6YNTIw6c1TcyaI1zb5wUlGI0HfXeYK8FoJsiEJYyafI7tYmiOzKfZKJB8I /EZ2EI1oWu8/0Or/n0cfGoHcNOyoctz+cv7JLibPa+7gqjIDDEZtjbF8/fuo+VNrAHzm fLPPih8gpAhasWYoRuEYv5NpfREwY2JNQxfRRMV0HOZCgNk07uvRWWiMZ85wjVKy1x85 Dtu3ERNL7f0oo/4UYGZwUDLoht8JWBeJNMMsOLZEcj61I9ZID6tnCXWXscaZC3OQwjFc UOdaNncnwwF4S2NK/p0HaG8Rwh/E08GH1DJ2YEF3BodfID3Eyo+TyxsAZhekjg0SLYGy 6pKw== 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=J03UqeBP8rNnazFggPBxtMyPdkfsUcFaI+RcGcDWfVs=; b=vCZcT6XNzsGzcYKIuiBITTeHOE5zYWi40aK6DyTC0RNrZlgXRz2d7Anp0Hzj/q5n/O eJ8KnlwkE0Qkw4u1YCFBIA9OMIPTwSvtbTAmLl5yGFxdOoOV+G1OVprq3TZXk+TNBaWD ja15LVIu+fm28CQCvepnwyiE3YdD59zHLeko8xrXSgY6MpVG231BxSKt/G+tNl6Zzu13 jsNUR8tZMaDAx9paiLfi+yPC7AD7JKiQtF/vdDh4SOBAO59YSv5s3Qt+mfnQnriBF8ls IvdYEBTRi5ifkFQfoXph/kZEjT1FfTfKhF8CVj6JYJ8q7zG2U9/4/wZhumGx4H2GME+k sIvg== X-Gm-Message-State: ANoB5pnmDbkO67vWaIkw1Rd44XAUL3oMQbRbRWmzs6mw3MufCQBzP40V hz2fup52tBNzxjlRz7QCBFGPCsmvLb3cgBeQ X-Google-Smtp-Source: AA0mqf7NTYqORoARDccc8dPXgTrkybhzof//su6HfubqKOkWCzr0VNmCRvNMABYRzts9o7f7GEdovQ== X-Received: by 2002:a17:903:1109:b0:185:441f:70a1 with SMTP id n9-20020a170903110900b00185441f70a1mr41745092plh.38.1671168646863; Thu, 15 Dec 2022 21:30:46 -0800 (PST) Received: from crass-HP-ZBook-15-G2.lan ([37.218.244.251]) by smtp.gmail.com with ESMTPSA id u4-20020a17090341c400b00187033cac81sm577714ple.145.2022.12.15.21.30.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Dec 2022 21:30:45 -0800 (PST) From: Glenn Washburn To: "grub-devel @ gnu . org" , Daniel Kiper Cc: Glenn Washburn Subject: [PATCH v4 09/15] gdb: Conditionally run GDB script logic for dynamically or statically positioned GRUB Date: Thu, 15 Dec 2022 23:29:32 -0600 Message-Id: <20221216052938.224564-10-development@efficientek.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221216052938.224564-1-development@efficientek.com> References: <20221216052938.224564-1-development@efficientek.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=development@efficientek.com; helo=mail-pl1-x629.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: Fri, 16 Dec 2022 05:30:51 -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 f901975e15..1a3dcbd57d 100644 --- a/grub-core/gdb_grub.in +++ b/grub-core/gdb_grub.in @@ -113,7 +113,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