From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1p5iNK-0007UB-5I for mharc-grub-devel@gnu.org; Thu, 15 Dec 2022 02:09:50 -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 1p5iNF-0007TT-6B for grub-devel@gnu.org; Thu, 15 Dec 2022 02:09:46 -0500 Received: from mail-qt1-x834.google.com ([2607:f8b0:4864:20::834]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p5iND-00083X-O6 for grub-devel@gnu.org; Thu, 15 Dec 2022 02:09:44 -0500 Received: by mail-qt1-x834.google.com with SMTP id ay32so4468356qtb.11 for ; Wed, 14 Dec 2022 23:09:43 -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=2tetZoigOeC7HpQGugXdZx53Iyui5LzB7Pitsekws3s=; b=VinNGnlbBUyC1qNH52xazQqYOab1OnwbizLqEWhGkev3NfDDZ4oU1uVjFW6hLXRfj6 WbHjhutmCXodk2mXzYawfJIOtBwAs3B/Y73Qcb982RdDcX0JzBFq3ami4A3SEdgsU23X nUJaamTRS4zOQYciUSgygpaT/RzM8TlXAaxFnWzpzhsiO5ZN0oPnxsQf/nmmAFPURoKh aEalnYE8zWD/+8VqCOyEP4z1QhPNEz1ZmfOqmuUCByKhgVxgnoLubPa7OREgMqeZYFuq z/WfikCyjJOamE7NhPAadf5as3DbdCKBhbklcYLZtaDXEs4eIPIWanhZsNT7NsCrRl4e AsvQ== 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=2tetZoigOeC7HpQGugXdZx53Iyui5LzB7Pitsekws3s=; b=GST3tN9dZoHhBCi98SphL87DL0YtWJyIWqwpY20PTae7gRHvOY0vWs6h4EqivqhjC8 BgiVetPHVx2XowT6yMT+0nsfp6VPT56Yc4r9D9tQIZGUc3FYXBgbt+ja0sQ5gpdbuKva eIktu0gfQ5PjU3ID7gmBwmS+WOFyBkUjc0cTL6E4QHSKfsqEcWKM7K0nlO5WmR0QiS/X 9PndrMj+BsvEEVlTmXyp+GZfsOpg3lIlS2c3mWTtKrZDNP0B432cASu3pLYAL9WVIcuk 7iMKT6Fb2gy6eiUjXD6S2h6K7/1/E7dnTjub2hzBg+gCwB9IGNc7dq1KAVHsMRYq2gWq RQKA== X-Gm-Message-State: ANoB5pmRsfDfXjhnFJZV/AfnUr3B/stkX1bVW0EO9WTVeE3EJuibH3yN 553NFt4SJwyk3zL6ca5NPTeSpbE9vjZ6R8+j X-Google-Smtp-Source: AA0mqf5o3l15LZrPwgbJMZmM6GGU4sS9xrkif/E4lKymDEyezBzZm5/t9KxLfEjafF1N9nX6hWM+8Q== X-Received: by 2002:a05:622a:2511:b0:3a7:f2b0:c4b7 with SMTP id cm17-20020a05622a251100b003a7f2b0c4b7mr16902430qtb.57.1671088182439; Wed, 14 Dec 2022 23:09:42 -0800 (PST) Received: from crass-HP-ZBook-15-G2.lan ([37.218.244.251]) by smtp.gmail.com with ESMTPSA id fy16-20020a05622a5a1000b003a7ec97c882sm3125068qtb.6.2022.12.14.23.09.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Dec 2022 23:09:41 -0800 (PST) From: Glenn Washburn To: grub-devel@gnu.org, Daniel Kiper Cc: Glenn Washburn Subject: [PATCH v3 06/15] gdb: Do not run load_module if module has already been loaded Date: Thu, 15 Dec 2022 01:07:41 -0600 Message-Id: <20221215070750.102591-7-development@efficientek.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221215070750.102591-1-development@efficientek.com> References: <20221215070750.102591-1-development@efficientek.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::834; envelope-from=development@efficientek.com; helo=mail-qt1-x834.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: Thu, 15 Dec 2022 07:09:47 -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 78219ea36e..521e3ae6ce 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