From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 2445F3858418 for ; Tue, 12 Dec 2023 11:15:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2445F3858418 Authentication-Results: sourceware.org; dmarc=pass (p=none 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 2445F3858418 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702379731; cv=none; b=e7NeDB97Nerg2Uol5JXfsT8toLeDaU0jKRPxEEtGKaNIA5mzBIAWWK3k3S3CVZp0bv9FSvwGptqf6UkuJaQhcE4sMQtj4k2WrCTjs4YDai7GhJGzxsFIjudffzPzgtz9sU9uyqot/3Asfzn6iiG2qza5KBZWeqHbIZilEbX4zos= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702379731; c=relaxed/simple; bh=lrK/ssg0EmuiF/aZgZ++aZAnoxOMBW91CnpeTomyEq0=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=qyy6XhXw9X8Un3QuFFBU33mlbU/3ckLojgZBl9Wro4AgfE355FX3kptZWoUlNELm0PWTWcEClS8E6yTVIKmA2OMMXgctnOuBVD5DE6i7Lvj5ZRU6Epd3bkn+BlylUuheYMrDqBDSR03K7zbATrt4un3BYjrDf9OnydWadKlvd5g= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702379729; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=8kDn+DKzC3+tdGd5HmnLMJWfvZ9U/rLKnBncUbhyPDo=; b=Qndeky0qLxZSyMer6xGxDcWocAjCU9cuF4E0Idgw/Wea3bXASd+VDdh40kwboIJDdaBT8+ 0hSAVoUCBawyoIbhHWmlhHtebLpCNQMLdlJOwg8HNn5AfBTm5kxqUrcuto6Ex1n3fuLHnH q2HwrfgC3fJPsemipLHOtrmiPgR4aQ8= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-662-h39q2YU7PBuaMe-K3GVrWQ-1; Tue, 12 Dec 2023 06:15:28 -0500 X-MC-Unique: h39q2YU7PBuaMe-K3GVrWQ-1 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-40c3f0f88e3so19459205e9.0 for ; Tue, 12 Dec 2023 03:15:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702379726; x=1702984526; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=8kDn+DKzC3+tdGd5HmnLMJWfvZ9U/rLKnBncUbhyPDo=; b=OJB1OUnkqQBY9GJ8cuq4DHFyhqPgIFWU+/BfG9wjqHzK7M02fetBRxrR/4NHEhN5PQ ux7zE0Jp0m3p3TUrV+5ouP6hlbgAMv2y8Y5mkugl2tIt3jY7dnM0/7P2G+rQ2mHYmiRG pBxbPOo4IJREiEyFndTixqG5f7Td8J4h8z3YpWqLPKB3OBMVy+oY1QPC3pEYoQ1gX417 PRrxlLJNKEu3jsLXUdycwzZO+g1+ATiR7xYYa7Bag+8Z5FWolhfBV50yjlSV7BbvajUF n5P/KCJsJngXCSsC1x1Ca72LLBR53oyVkZhJLJ6Nsr1pdSprCkKjsjye8hTmtaG2psaa fCDg== X-Gm-Message-State: AOJu0Yzo+GlvwzM97A1tpRG4otZO7lETdPY5bij7jcbTLlCZ28ZsjlHF ruIERsGH0F5QbVnZh5EpVRtyrtfOQ9mJznRmLIaQRiJlNVkBGW1zpaxIL7Y8k9e0nkrigSnMsih 5ZJML7eUUE1ISAJm3J0wWEaRslFON5L8HXvg05OAFhiidgn/o03G6p3WUxxVX4yPNnB/CFkiDwI NY X-Received: by 2002:a05:600c:444e:b0:40c:48d3:2adb with SMTP id v14-20020a05600c444e00b0040c48d32adbmr1468981wmn.63.1702379726258; Tue, 12 Dec 2023 03:15:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IHOXkf4ujORPhmVxcZus7NxPPprogJCl7ZT39j655R8Zfv6XRbN0uf9T6ggTyFCgcF+c9Sonw== X-Received: by 2002:a05:600c:444e:b0:40c:48d3:2adb with SMTP id v14-20020a05600c444e00b0040c48d32adbmr1468970wmn.63.1702379725749; Tue, 12 Dec 2023 03:15:25 -0800 (PST) Received: from localhost (105.226.159.143.dyn.plus.net. [143.159.226.105]) by smtp.gmail.com with ESMTPSA id az27-20020a05600c601b00b0040c34e763ecsm15165680wmb.44.2023.12.12.03.15.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 03:15:25 -0800 (PST) From: Andrew Burgess To: insight@sourceware.org Cc: Andrew Burgess Subject: [PATCH] switch away from using specify_exec_file_hook Date: Tue, 12 Dec 2023 11:15:22 +0000 Message-Id: <6abeb45e97d9004ec331e94cf2089af00553de76.1702379379.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: I had a go at testing this patch using make check-gdb TESTS="gdb.gdbtk/*.exp", but ran into numerous errors, I suspect that the gdbtk testing has not been run in a while, and it certainly doesn't appear to have kept up with changes to the GDB testsuite. If there's any particular testing that I should be running then just let me know. Otherwise, if we could merge this patch, then we can remove a couple of functions from GDB that are only used to support this one hook. --- Stop using specify_exec_file_hook to spot when the executable GDB is debugging changes, and instead use gdb::observers::executable_changed. The specify_exec_file_hook would call a function with the name of the executable as specified by the user, so long as the name of the executable wasn't empty, e.g.: (gdb) file exec_name would call the hook with 'exec_name', while: (gdb) file would not call the hook at all. The observer I'm proposing we switch too is slightly different. The observer is called with the program_space in which the executable changed, even in the empty filename case. The observer also receives a flag which indicates if GDB is loading a new executable, or is loading the same executable because the on-disk file changed. To reduce the chance of breakage, within insight, if the new observer function is called in the empty filename case I don't call into the TCL code, this ensures the TCL code is only called in the same cases a previously. The TCL code will be called with the full path to the executable rather than the partial string the user specified, however, the TCL code would (in some cases at least) look up the full executable path anyway, so I don't think the change should have a negative impact. For now I'm ignoring the reload_p flag, that is, I call into the TCL code both when the executable has completely changed, and when it's the same executable filename, but the on-disk file changed, I think this matches the behaviour before this patch. And finally, while looking at the TCL code, I spotted that a comment in interface.tcl relating to this code was slightly out of date, I've updated the comment. --- gdbtk/generic/gdbtk-hooks.c | 16 +++++++++++----- gdbtk/library/interface.tcl | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/gdbtk/generic/gdbtk-hooks.c b/gdbtk/generic/gdbtk-hooks.c index 75e89e7..fe42e7d 100644 --- a/gdbtk/generic/gdbtk-hooks.c +++ b/gdbtk/generic/gdbtk-hooks.c @@ -83,7 +83,7 @@ static void gdbtk_trace_start_stop (int, int); static void gdbtk_attach (void); static void gdbtk_detach (void); static void gdbtk_file_changed (const char *); -static void gdbtk_exec_file_display (const char *); +static void gdbtk_executable_changed (program_space *, bool); static void gdbtk_call_command (struct cmd_list_element *, const char *, int); static void gdbtk_target_pre_wait (ptid_t ptid); static void gdbtk_target_post_wait (ptid_t event_ptid); @@ -140,6 +140,8 @@ gdbtk_add_hooks (void) "gdbtk-hooks"); gdb::observers::target_post_wait.attach (gdbtk_target_post_wait, "gdbtk-hooks"); + gdb::observers::executable_changed.attach (gdbtk_executable_changed, + "gdbtk-hooks"); /* Hooks */ deprecated_call_command_hook = gdbtk_call_command; @@ -157,7 +159,6 @@ gdbtk_add_hooks (void) deprecated_pre_add_symbol_hook = gdbtk_pre_add_symbol; deprecated_post_add_symbol_hook = gdbtk_post_add_symbol; deprecated_file_changed_hook = gdbtk_file_changed; - specify_exec_file_hook (gdbtk_exec_file_display); deprecated_attach_hook = gdbtk_attach; deprecated_detach_hook = gdbtk_detach; @@ -732,11 +733,16 @@ gdbtk_file_changed (const char *filename) gdbtk_two_elem_cmd ("gdbtk_tcl_file_changed", filename); } -/* Called from exec_file_command */ +/* Called from exec_file_attach when the executable changes. PSPACE is + the program space in which the executable was changed. RELOAD_P is + true if the executable didn't actually change, but instead GDB detected + that the on-disk file change, so reloaded the current executable. */ static void -gdbtk_exec_file_display (const char *filename) +gdbtk_executable_changed (program_space *pspace, bool reload_p) { - gdbtk_two_elem_cmd ("gdbtk_tcl_exec_file_display", filename); + if (pspace->exec_filename.get () != nullptr) + gdbtk_two_elem_cmd ("gdbtk_tcl_exec_file_display", + pspace->exec_filename.get ()); } /* Called from error_begin, this hook is used to warn the gui diff --git a/gdbtk/library/interface.tcl b/gdbtk/library/interface.tcl index c69e2f0..da0bcae 100644 --- a/gdbtk/library/interface.tcl +++ b/gdbtk/library/interface.tcl @@ -798,7 +798,7 @@ proc gdbtk_tcl_file_changed {filename} { # ------------------------------------------------------------------ # PROCEDURE: gdbtk_tcl_exec_file_display -# This hook is called from exec_file_command. It's purpose +# This hook is called from exec_file_attach. It's purpose # is to setup the gui for a new file. Note that we cannot # look for main, since this hook is called BEFORE we # read symbols. If the user used the "file" command, base-commit: 0b35bf269b3625d05764ebaeec45b32a2ac03321 -- 2.25.4