From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id ETjsL1fUL2ruJggAWB0awg (envelope-from ) for ; Mon, 15 Jun 2026 06:30:47 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=TDKUA30N; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id BFDF41E098; Mon, 15 Jun 2026 06:30:47 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id ECD831E024 for ; Mon, 15 Jun 2026 06:30:46 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2ECE04C31830 for ; Mon, 15 Jun 2026 10:30:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2ECE04C31830 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=TDKUA30N Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id B1DE74BCA40C for ; Mon, 15 Jun 2026 10:29:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B1DE74BCA40C Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B1DE74BCA40C Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1781519387; cv=none; b=sxQ/vhw3FNQUbgt9E24vFgwUF4M8b/OfH6pKe1FAyNRowcoqEG359q99vfZcxNS2i1VizguRo71BecQGkCl+onZbbGTgMVd8pS7PhYpGLnEI5zkqNOBruHXIN4iSRor4tQOew8xLvw1Jg8zs1AXJ+wu7OGh2/Otp6DjZUxu3UEE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1781519387; c=relaxed/simple; bh=W0kkYm8cER4BFsxsIirmERtCFQp48p7h3rGEWhMSHPI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=bB53RQz/8y3pQLMAkxIMZYIHPUyr2oKRT1txNdNpcvO7TsqlaBWxYXN7bhFJmMGU86CNjHSrdgR8Qym1WCnQWVoG2bm1k/hNuduv86dSA/fXtdT0O3o6w4hWA7syP+ZxAk1nLx1jw0HBdB1u/LyDp7mHMFI7Q2oWLaFAklDUVOE= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=TDKUA30N DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B1DE74BCA40C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1781519387; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=rJQErRO1L6wexlNDVwqmp7TufYk7IqxBtYfSPO4LYW4=; b=TDKUA30NXusRJLP5ENkgeHwuOZLOJavi+GjUWSKykpziIkNBPBTZo4BG4IiaB4fwFOHY1S WYsbHFGTltMiVa4ni7S7qhVDi4gVBK/Fk+++dyel0GxSVM8SHj3J6pfkG9zwYG6Rm21qvw +mDa3cJCVckSdCllQChaaFPh4HadQ7s= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-610-4NoE1Ge-MuWDzON91AKnvA-1; Mon, 15 Jun 2026 06:29:45 -0400 X-MC-Unique: 4NoE1Ge-MuWDzON91AKnvA-1 X-Mimecast-MFC-AGG-ID: 4NoE1Ge-MuWDzON91AKnvA_1781519384 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-45ef5e38a18so1476935f8f.1 for ; Mon, 15 Jun 2026 03:29:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781519384; x=1782124184; h=mime-version:message-id:date:references:in-reply-to:subject:to:from :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=rJQErRO1L6wexlNDVwqmp7TufYk7IqxBtYfSPO4LYW4=; b=qY/UXANovuOEoLUaXsXGq0WZcypWeOqOp+xsWXaWVk9rA2/b0AfExToj9yWEkBR/WT ptIBqbr4XaTZy2iF2KdTL4inU8SL9YKn4epLI7ZB8VlzQSnovu0Ugp14J3Pp/BKEkwn3 /uMZv5AFtMNf5Om247DHpT8qz38QrGm1Pcu9owXtqADcADq8YIdHwhwWDCs750p1Bxvr WMPV3BBInlKkkFPWJb8wDA5ClIq9pP2YB+lpYHCfAgmixXXaUNqCl2NcoeXV/Ga4jlyK /VVZeBwDHYqkueCNBE3DeMo9iYM1AkoKvg2sysLDZ0sekBphTr6fwKKkes/43NJ81mFc MIoA== X-Forwarded-Encrypted: i=1; AFNElJ+yThERYeRau9JdG5ws0lMHfDZjaN3aTXzLwbuR8wZ59Oa1dmJMD11Aota8XPBFfA/JRYoeftcb/vctbg==@sourceware.org X-Gm-Message-State: AOJu0YzxZBQBXB2430Xt12M375526E8LS/aM2t27NMSqZfGboSxHmH4Q vXv5jYu2yQ/cSJzNsFqllNTvYAS9cTEpga/BSxkwkdeuOGSoFyUDZDmqTE4GQE2WXat4hwuvhDd B2Q4mqJWOxdobgdx4/QjtjcZmCwDt/N+zA1njwcb7sP+7JKfXMxksYg4EVK3AX0mSHHP3AIM= X-Gm-Gg: Acq92OH07+iGxngtkSniNvlIgmLtF21S4hUjLKfOLk/ZH8/Cg2wGJXxUT8vA/5daO/e 1TQ/KSFMYR4NfltkbuJE9VI+0PVELLcnHTsX5YYeXlU0hMEimBhSyykrRj/YkLwOBgXVUCBYHCa XU+VdxcP/sSizWC7Qf95/vyn4I/me6bVQC6YPPOY7Ukd5gRJ/0IdZNNeaJGtDYZ8MhxGuV4VLHG bsQjM5x6d5ttcGXVhfyOeVHd5mAELBSKra6Rrm98YvO6rzpXxxO+Ct+YGJ8h2DC5ARDY3rbAzjN QETyZeoCUugliGgo56ECdjGgK6zBQu49cZ2QqgRUeDd2hM+IDozg8ZNe4IX1Cy2M46uuQKGw/Kv XZFl9eDs+TPNTWY2Z66MG/wkULSP1QHtT2hUDrSRi X-Received: by 2002:a05:6000:178e:b0:45e:f31a:7ae6 with SMTP id ffacd0b85a97d-46077f2bffcmr12861019f8f.30.1781519384143; Mon, 15 Jun 2026 03:29:44 -0700 (PDT) X-Received: by 2002:a05:6000:178e:b0:45e:f31a:7ae6 with SMTP id ffacd0b85a97d-46077f2bffcmr12860975f8f.30.1781519383536; Mon, 15 Jun 2026 03:29:43 -0700 (PDT) Received: from localhost (19.81.93.209.dyn.plus.net. [209.93.81.19]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4606f2cd6c2sm33418071f8f.30.2026.06.15.03.29.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jun 2026 03:29:43 -0700 (PDT) From: Andrew Burgess To: Pedro Alves , gdb-patches@sourceware.org Subject: Re: [PATCHv2 2/3] gdb: introduce program_space::get_entry_point_info function In-Reply-To: References: <41fe591d58ba010fa771e80ca674b61e30feef2f.1780942441.git.aburgess@redhat.com> <864cefb52d208dd8aac6b1b5f452cadad7546af8.1781214731.git.aburgess@redhat.com> Date: Mon, 15 Jun 2026 11:29:42 +0100 Message-ID: <87fr2op04p.fsf@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: n6OjVAN4QE4LQiWifTrVnDpPS-A0x1b5pIL3fT6aXRk_1781519384 X-Mimecast-Originator: redhat.com Content-Type: text/plain 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~public-inbox=simark.ca@sourceware.org Pedro Alves writes: > On 2026-06-11 22:59, Andrew Burgess wrote: > >> >> +/* See solib.h. */ >> + >> +std::optional >> +svr4_solib_ops::inferior_entry_point_address () const >> +{ >> + std::optional interp_name_holder >> + = svr4_find_program_interpreter (); >> + >> + /* No interpreter means this is a static executable. Ask the >> + program_space for the entry address within the main executable. */ >> + if (!interp_name_holder.has_value ()) >> + return m_pspace->exec_entry_point_address_if_available (); >> + >> + /* If we can find a solib that matches the interpreter name then we can >> + use that to find the actual entry address of the inferior. */ >> + const solib *interp_solib = nullptr; >> + const char *interp_name = (const char *) interp_name_holder->data (); >> + for (const solib &so : m_pspace->solibs ()) >> + { >> + if (svr4_same_name (interp_name, so.original_name.c_str ())) >> + { >> + interp_solib = &so; >> + >> + const objfile *objfile = so.objfile; >> + if (objfile != nullptr && objfile->per_bfd->ei.entry_point_p) >> + { >> + const entry_info &ei = objfile->per_bfd->ei; >> + return (ei.entry_point >> + + objfile->section_offsets[ei.the_bfd_section_index]); >> + } >> + } >> + } >> + >> + gdb_bfd_ref_ptr tmp_bfd; >> + target_ops_up tmp_bfd_target; >> + try >> + { >> + tmp_bfd = solib_bfd_open (interp_name); >> + >> + /* Failed to open the interpreter BFD. */ >> + if (tmp_bfd == nullptr) >> + return {}; >> + >> + tmp_bfd_target = target_bfd_reopen (tmp_bfd); >> + } >> + catch (const gdb_exception &ex) >> + { > > Swallows Ctrl-C. (I see you're just copying this from elsewhere.) > >> + return {}; >> + } >> + >> + CORE_ADDR entry_addr >> + = exec_entry_point (tmp_bfd.get (), tmp_bfd_target.get ()); >> + >> + /* We found the solib for the interpreter, but we don't have a >> + corresponding objfile, or the objfile doesn't have entry point >> + information. Maybe symbols haven't been loaded yet? */ >> + if (interp_solib != nullptr) >> + { >> + gdb_assert (interp_solib->objfile == nullptr >> + || !interp_solib->objfile->per_bfd->ei.entry_point_p); >> + >> + CORE_ADDR load_addr >> + = this->lm_addr_check (*interp_solib, tmp_bfd.get ()); >> + >> + return load_addr + entry_addr; >> + } >> + >> + /* We could not find a solib corresponding to the interpreter, this might >> + mean that the name didn't match for some reason, or maybe GDB has >> + failed to create a solib due to some other issue reading the solib >> + list from the inferior. >> + >> + If we got here we have managed to open the expected interpreter on >> + disk though, so we can try using the AT_BASE value. */ >> + CORE_ADDR load_addr; >> + if (target_auxv_search (AT_BASE, &load_addr) > 0) >> + { >> + int addr_bit = gdbarch_addr_bit (current_inferior ()->arch ()); >> + >> + /* Ensure LOAD_ADDR has proper sign in its possible upper bits so >> + that `+ load_addr' will overflow CORE_ADDR width not creating >> + invalid addresses like 0x101234567 for 32bit inferiors on 64bit >> + GDB. */ >> + if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT)) >> + { >> + CORE_ADDR space_size = (CORE_ADDR) 1 << addr_bit; >> + >> + gdb_assert (load_addr < space_size); >> + >> + /* ENTRY_ADDR exceeding SPACE_SIZE would be for prelinked >> + 64bit ld.so with 32bit executable, it should not happen. */ >> + if (entry_addr < space_size >> + && entry_addr + load_addr >= space_size) >> + load_addr -= space_size; >> + } >> + >> + return load_addr + entry_addr; >> + } > > I wonder whether just looking at AT_BASE, which points at an ELF, and then > adding elf_header->e_entr, wouldn't be simpler than all of this. > We already use Elf32_External/Elf64_External structs in the file, so maybe > the manual ELF peeking is OK. > > Alternatively, of lot of that code looks similar to enable_break. Maybe > it could be refactored to be shared. Or enable_break could cache the > entry address. > > >> +# Use 'readelf' to extract the entry point address from TESTFILE. >> +proc get_exec_entry_address { testfile } { >> + set readelf_program [gdb_find_readelf] >> + set command "exec $readelf_program -Wh [standard_output_file $testfile]" > > If you use "objdump -f" instead, this has a better chance of working on Windows PE/COFF too (eventually): > > $ objdump.exe -f ./foo.exe > > ./foo.exe: file format pei-x86-64 > architecture: i386:x86-64, flags 0x0000013b: > HAS_RELOC, EXEC_P, HAS_DEBUG, HAS_SYMS, HAS_LOCALS, D_PAGED > start address 0x00000001400013f0 >> +# Start TESTFILE using 'starti'. Check if the 'backtrace' command >> +# prints any additional frames; we don't expect any. >> +# >> +# When IS_DYNAMIC is true then TESTFILE is a dynamically linked >> +# executable, otherwise TESTFILE is statically linked. >> +proc run_test { testfile is_dynamic } { >> + clean_restart $testfile >> + >> + set exe_entry_addr [get_exec_entry_address $testfile] >> + >> + # The inferior entry address is always unknown before starting the >> + # inferior as at the point GDB has no solib_ops, and it is only >> + # through that that we figure out the inferior entry address. >> + check_maint_info_entry_addr "" $exe_entry_addr \ >> + "check 'maint info entry-address' before inferior starts" >> + >> + # Start inferior with 'starti' and then wait for a prompt. >> + gdb_starti_cmd >> + gdb_test "" ".*" "prompt after starti" >> + >> + # Only svr4 targets currently support querying the inferior entry >> + # address. >> + if {[istarget *-linux*]} { > > There are more svr4 targets than linux. I think this style of allow-list has > a good chance of never getting updated. Deny-lists are better, IMHO. If the > test fails on some port, that might trigger someone to add the feature > there. Hey Pedro, I'm still looking at your other feedback, but before I start making this specific change, I just wanted to clarify how you see this as being different from what I have right now. If I write this as a deny list, e.g. if { ![istarget ....] && ![istarget ....] } { # Run tests. } Is there not the same problem? We rely on someone realising that the reason the test isn't run on their target is some missing GDB functionality, and them adding the functionality and removing the `istarget` block for their target. Another option would be for me to just not add any test skipping right now. I know this will lead to the test failing for some targets as the new feature is only implemented for svr4 targets. Then, if someone on a failing target cares, they can add the missing feature. This approach feels a bit mean, I don't like adding failing tests for others, but it does draw attention to the problem. I wonder if a better approach would to stick with my allow list, but add an 'unsupported' call in the else block. Maybe someone on e.g. Windows, will periodically look at tests that report 'unsupported' and see if there is anything that could be done? If 'unsupported' is the wrong type then I can use whatever you prefer. I agree with your feedback on svr4 being wider than just Linux, I'll add a helper function for `is_svr4_target` to lib/gdb.exp and then make use of that, the svr4 list can then be improved over time. Thanks, Andrew