Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1npeTL-0006wh-HD for mharc-grub-devel@gnu.org; Fri, 13 May 2022 19:13:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56114) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1npeTK-0006sy-5E for grub-devel@gnu.org; Fri, 13 May 2022 19:13:22 -0400 Received: from mail-ua1-x935.google.com ([2607:f8b0:4864:20::935]:39450) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1npeTI-0007QW-Jl for grub-devel@gnu.org; Fri, 13 May 2022 19:13:21 -0400 Received: by mail-ua1-x935.google.com with SMTP id s1so3724024uac.6 for ; Fri, 13 May 2022 16:13:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VN6VRks7gs0fFmsYUxKeMS+oWkvkYahR/zhPONvfM2Q=; b=p6mwVXMLXTbFM6DUlAhdN/oBGH86oHFhQ5wFKdRNtk6r/3o5X4WwEallAp2TaoOZPc AO6ftJ6EWQa6+DrcScnrU15drs5YVeEZxR8t3+y7TFJEAsK6kmjsvJtmmaDO+Khg/0Tq IJP73Qh3ugT5nH2n0xROibC7KUW1Q6ELv9tdkRj32DyvDp2TjdM1B7q1PGSktSQ8qhcD L92LaMj1CCxJ4NH7+hQiVi+7ODbouw1tkEE/5UvB92tSpgd7h4k/acAKXIc/Lop+iugo gaOMQp292BWJXRS+1+GcITTTCGH08qZoB/8zc4TQbUP2hV3zSlic+ZA49yG+g6xVsaUy B3Gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VN6VRks7gs0fFmsYUxKeMS+oWkvkYahR/zhPONvfM2Q=; b=W+kfP1xHyGfPXBvqW5I5jlXcewgH3quv7b9JBTGvpi3BuIwfDbRih+cRegrwSLmhrd pghA5Pa9B5b4baSGjGjROEezy18n6aTzmCuBvbza//ExUCHpidSYcOTBKVPXqBxSeuzt RYs+hXzLWE/M9fZI7PXL1ttl1A7pEMy+PZVaeQuwrgQZf1VF89sLRsJ9KnzuSyIkKNmT tBzb5JOgWhb7zcTFFVOyBj8xaz5FH9dskW1orbJgsdMuTjiz6GIp97YZ99YVM0U26L/5 dE4jiVtzHwx27WS3C3fuK6VaspF7mrHPXASkHOie/SyWl8WEOdd0afrAzCCWv52sy57n Huxw== X-Gm-Message-State: AOAM530yDX9UKZMwRtL50Lw8/RN7fKMyVKEMntN6No59esYPInICgjGa hc6FTKhWz7o2Yu0WkvWhbr6FslR5V408vmX0 X-Google-Smtp-Source: ABdhPJy9TXUHIJu26oSZsBDhfXZYE9HeTWJXLiGtt3dANNu8DJcocSopDVFft3SM1Qyr+jqJ6jxVnw== X-Received: by 2002:ab0:4461:0:b0:35d:36b6:3867 with SMTP id m88-20020ab04461000000b0035d36b63867mr3142431uam.37.1652483599449; Fri, 13 May 2022 16:13:19 -0700 (PDT) Received: from localhost.localdomain ([37.218.244.249]) by smtp.gmail.com with ESMTPSA id 129-20020a1f1387000000b0034e6f1fd067sm423865vkt.49.2022.05.13.16.13.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 16:13:18 -0700 (PDT) From: Glenn Washburn To: grub-devel@gnu.org, Daniel Kiper Cc: Peter Jones , Robbie Harwood , Glenn Washburn Subject: [PATCH v2 06/15] gdb: Do not run load_module if module has already been loaded Date: Fri, 13 May 2022 18:12:39 -0500 Message-Id: <6ad80d3538a2efd08529612800cd17fbddefeac2.1652482822.git.development@efficientek.com> 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::935; envelope-from=development@efficientek.com; helo=mail-ua1-x935.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, T_SCC_BODY_TEXT_LINE=-0.01 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: Fri, 13 May 2022 23:13:22 -0000 Fix an issue where the command load_module is being run multiple times. This happens because grub_dl_add can get called multiple times by GRUB (eg. a user runs "insmod " multple times). This causes the symbols to get added multiple times. Instead, first check if the modules has already been loaded, and not run load_module in the automatic runtime module symbols loader command, runtime_load_module, if it has. This is done using the new GDB command get_module which traverses the loaded module list checking if a given string matches the each module name. It returns the address of the module if found in the $ret GDB variable, otherwise NULL. Also add new GDB command num_modules that sets the variable $ret to the number of modules loaded. Signed-off-by: Glenn Washburn --- grub-core/gdb_grub.in | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/grub-core/gdb_grub.in b/grub-core/gdb_grub.in index 78219ea36..521e3ae6c 100644 --- a/grub-core/gdb_grub.in +++ b/grub-core/gdb_grub.in @@ -82,7 +82,10 @@ define runtime_load_module commands silent fr 1 - load_module mod + get_module mod->name + if ($ret == 0) + load_module mod + end cont end cont @@ -92,6 +95,30 @@ document runtime_load_module Load module symbols at runtime as they are loaded. end +define get_module + set $this = grub_dl_head + while ($this != 0 && grub_strcmp($this->name, $arg0)) + set $this = $this->next + end + set $ret = $this +end +document get_module + Given a module name print its address or NULL if not loaded. +end + +define num_modules + set $this = grub_dl_head + set $i = 0 + while ($this != 0) + set $i = $i + 1 + set $this = $this->next + end + set $ret = $this +end +document num_modules + Given a module name print its address or NULL if not loaded. +end + ### set confirm off -- 2.34.1