From patchwork Mon Dec 9 13:05:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephan Rohr X-Patchwork-Id: 102682 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6D0303857B9F for ; Mon, 9 Dec 2024 13:07:01 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) by sourceware.org (Postfix) with ESMTPS id 4746C3858431 for ; Mon, 9 Dec 2024 13:05:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4746C3858431 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4746C3858431 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.19 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1733749538; cv=none; b=sgzBaU4sdLtMmqtMDw5R3i0JG0LI8JCvMNVtFzuAAxzWm3FfBpisQDrNqx2kAfSyZdkRCBkceDrCeLzKok2V4soYiOv8bsQvjOgTBfnH0zT6wyIedeaWuKCDcicfwLbFGaU4+jeUOpkPZJ6/8bxwy6k4WlKvi+B/VWmtFMgywPc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1733749538; c=relaxed/simple; bh=mlAhua88LZdrDEbqxvIRJMzEGyHmAw0HFYRZiwqkqaw=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=cOs5EvHibRMX2BE1Rtr9g+i8U57/Aq4YJw6J9v0przCAC8EJvMZpJwrja3J+EX9zdfPN6fvxQVYsw0AzCFgVSr1xEpSqpPl3rSzTNQGb7cl/WR36eFcDGc5Znjvr89r7RndVtP7JcogGNL7PctIh6Ptc0ufkT9xe+YakM+PgGnU= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1733749538; x=1765285538; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mlAhua88LZdrDEbqxvIRJMzEGyHmAw0HFYRZiwqkqaw=; b=PtMsni26OuG9vRCD9X0ZSfMc0pxjpr4GWUnlfzN2EDMVzAyNteu0S6K1 YXncrAD2kGfn298v8u3fwY7qu0FU/iyosyCImVjuz2dRD12l5VxZZAakn +0hIx9ibYxp16xL7bl23YI1PMZIuafHSqte/JAYn1uoNlgZpwyPgSvism OYG3gQulxL6hTxpbkG3gm5CptpWgWTIBbm+8XuDmJTAgyow/QjnQfNi3H cCY493nbhe9iF3aVIjkXyf8LQsTZTRbJwH+gH5COjRssVBCw05JG5lHFZ OcvlOBIPyxhM+yg8nf8blxn1nuQj5RkwE2ZHXOEG8uCz1azoiHcAGd2ws A==; X-CSE-ConnectionGUID: Gnn6sQ7fQ4mrnw3L5/+L1w== X-CSE-MsgGUID: vtZKnORiTIuDdzVlqMZJLQ== X-IronPort-AV: E=McAfee;i="6700,10204,11281"; a="33384386" X-IronPort-AV: E=Sophos;i="6.12,219,1728975600"; d="scan'208";a="33384386" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Dec 2024 05:05:37 -0800 X-CSE-ConnectionGUID: aNXGfMIPTqmZf7pVR991pQ== X-CSE-MsgGUID: 0jiR0vhtR3WO47Ij6tk6dg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,219,1728975600"; d="scan'208";a="100105889" Received: from 984fee0031af.jf.intel.com (HELO localhost) ([10.165.54.65]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Dec 2024 05:05:37 -0800 From: Stephan Rohr To: gdb-patches@sourceware.org Cc: guinevere@redhat.com Subject: [PATCH v2 1/1] gdb: abort start command if there is no symbol for 'main_name ()' Date: Mon, 9 Dec 2024 05:05:28 -0800 Message-Id: <20241209130528.312719-2-stephan.rohr@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241209130528.312719-1-stephan.rohr@intel.com> References: <20241209130528.312719-1-stephan.rohr@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org From: "Rohr, Stephan" GDB aborts the 'start' command if the minimal symbols cannot be resolved. On Windows, GDB reads the minimal symbols from the COFF header of the PE file. The symbol table is deprecated and the number of symbols in the COFF header may be zero [1]. For example, the LLVM clang compiler for Windows MSVC can be instructed to generate DWARF: clang++ -g -O0 -gdwarf -fuse-ld=lld test.cpp -o test_clang The corresponding COFF file header shows: FILE HEADER VALUES 8664 machine (x64) E number of sections 66E889EC time date stamp Mon Sep 16 21:41:32 2024 FB400 file pointer to symbol table 0 number of symbols F0 size of optional header 22 characteristics GDB is not able to read the minimal symbols; the `start' command fails with an error: (gdb) start No symbol table loaded. Use the "file" command. Manually inserting a breakpoint in main works fine: (gdb) tbreak main Temporary breakpoint 1 at 0x14000100c: file test.cpp, line 6. (gdb) run Starting program: C:\test-clang Temporary breakpoint 1, main () at test.cpp:6 6 std::cout << "Hello World.\n"; Fix this by testing if a symbol for `main' is available instead of checking the minimal symbol table: (gdb) start Temporary breakpoint 1 at 0x14000100c: file test.cpp, line 6. Starting program: C:\test-clang Temporary breakpoint 1, main () at test.cpp:6 6 std::cout << "Hello World.\n"; (gdb) [1]: https://learn.microsoft.com/en-us/windows/win32/debug/pe-format Reviewed-By: Guinevere Larsen --- gdb/infcmd.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/gdb/infcmd.c b/gdb/infcmd.c index 5c0e3f51162..7e18a8de3a8 100644 --- a/gdb/infcmd.c +++ b/gdb/infcmd.c @@ -516,10 +516,15 @@ run_command (const char *args, int from_tty) static void start_command (const char *args, int from_tty) { - /* Some languages such as Ada need to search inside the program - minimal symbols for the location where to put the temporary - breakpoint before starting. */ - if (!have_minimal_symbols (current_program_space)) + /* Abort the start command if `main` cannot be resolved, e.g., there + is no symbol for main. Some languages such as Ada need to search + inside the program minimal symbols for the location where to put + the temporary breakpoint before starting. */ + struct symbol *sym + = lookup_symbol_search_name (main_name (), nullptr, + SEARCH_FUNCTION_DOMAIN).symbol; + + if (sym == nullptr) error (_("No symbol table loaded. Use the \"file\" command.")); /* Run the program until reaching the main procedure... */