From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd2c.google.com (mail-io1-xd2c.google.com [IPv6:2607:f8b0:4864:20::d2c]) by sourceware.org (Postfix) with ESMTPS id 1F3FB385771D for ; Tue, 25 Jul 2023 13:49:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1F3FB385771D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-io1-xd2c.google.com with SMTP id ca18e2360f4ac-7835971026fso234786639f.3 for ; Tue, 25 Jul 2023 06:49:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1690292982; x=1690897782; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ioaRpsRRTqZkgTjNqBqG+Kl/Iv9vMK04n7UwsWy6lF8=; b=S1a0kwcNC3iXa94qOXs2zvTWEpxim0LWej9fWxuTzz/HClm2OnIHaa6VqZ4jNa2YOA 8UC2t58XoBVgsbYovYbtqyVpmViMb+XLE1OOrIObXKsFU5z4TgdWNXIejfrFfudmP4P2 odCAKvcLPQ1VPBm6rHLxoF7eX/jUDzJavbUkJ6mACFTWikYRhBLeQ4n7juZc+32wkilA pCxOUgF8JYTZownjBh23ydKo33jx0BLhOGSiCPwAUR1b20ANcsx8TNfWo0oSIJeqXQf/ 7NPEkMs3MtgsBVZxs53BjPGVn/B4sqGzl9z52bWeFois8gRh0u/qs80h5GtTwBgt4hd6 5RsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690292982; x=1690897782; h=to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ioaRpsRRTqZkgTjNqBqG+Kl/Iv9vMK04n7UwsWy6lF8=; b=J0KVypbrgHIBiz09T87OruOmWJASGhAAPD6LG1Zx7OAR7+59aYAuM5E3s/jCIpJp1V qxK9A79tOm09Ljr2WBR4JdiReqo8V4uWi6qKxUTy5Xd2Q3bpmMA8jiEXJAeYxnW25ziu E4I3cDslsc/7VWWtbSdrz4MGswM0tRqX4SdVEfikybLwlReXbkUxQmFSZBetqhEzI1du 9H4bYViRf8zjTXzOnUjtUfcbLZyaRJIA7iLGfjiU0Cw2opeWRmXrpu6wLQEFiZ/WOqb9 w62cVEIuarePhQYVm7mR92thZL5fbIWBKJi1kRZaPAt5akcSYxzztrUTnl/eX32NlS8N POoQ== X-Gm-Message-State: ABy/qLYI/vB4LJGjDcxG7P0cWkvukBcffVQ9UJGBghBoX8oDrVKWOQOZ bqNK4Sbvev4t82iqAjc1Pvj/oo/JLHxONVMlr4BMpQ== X-Google-Smtp-Source: APBJJlHvxNkWyjDyqy1vDFdT1BgAiBIpj9UcAla1LBBmT9ExizbD2SWDO1oX6b5x8kFuqqCVeU6C9g== X-Received: by 2002:a5e:a60c:0:b0:787:f94:5133 with SMTP id q12-20020a5ea60c000000b007870f945133mr2493160ioi.2.1690292982171; Tue, 25 Jul 2023 06:49:42 -0700 (PDT) Received: from localhost.localdomain (75-166-135-140.hlrn.qwest.net. [75.166.135.140]) by smtp.gmail.com with ESMTPSA id c3-20020a02a403000000b00418a5e0e93esm3595018jal.162.2023.07.25.06.49.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jul 2023 06:49:41 -0700 (PDT) From: Tom Tromey Date: Tue, 25 Jul 2023 07:49:41 -0600 Subject: [PATCH 4/6] Full paths in DAP stackTrace responses MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20230725-dap-bt-path-v1-4-bb015b0d8e54@adacore.com> References: <20230725-dap-bt-path-v1-0-bb015b0d8e54@adacore.com> In-Reply-To: <20230725-dap-bt-path-v1-0-bb015b0d8e54@adacore.com> To: gdb-patches@sourceware.org X-Mailer: b4 0.12.3 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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: Vladimir Makaev noticed that, in some cases, a DAP stackTrace response would include a relative path name for the "path" component. This patch changes the frame decorator code to add a new DAP-specific decorator, and changes the DAP entry point to frame filters to use it. This decorator prefers the symtab's full name, and does not fall back to the solib's name. I'm not entirely happy with this patch, because if a user frame filter uses FrameDecorator, it may still do the wrong thing. It would be better to have frame filters return symtab-like objects instead, or to have a separate method to return the full path to the source file. I also tend to think that the solib fallback behavior of FrameDecorator is a mistake. If this is ever needed, it seems to me that it should be a separate method. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30665 --- gdb/python/lib/gdb/FrameDecorator.py | 111 +++++++++++++++++++++-------------- gdb/python/lib/gdb/frames.py | 14 ++++- 2 files changed, 78 insertions(+), 47 deletions(-) diff --git a/gdb/python/lib/gdb/FrameDecorator.py b/gdb/python/lib/gdb/FrameDecorator.py index c4a7806e434..22d5fa4d0a9 100644 --- a/gdb/python/lib/gdb/FrameDecorator.py +++ b/gdb/python/lib/gdb/FrameDecorator.py @@ -16,34 +16,8 @@ import gdb -class FrameDecorator(object): - """Basic implementation of a Frame Decorator""" - - """ This base frame decorator decorates a frame or another frame - decorator, and provides convenience methods. If this object is - wrapping a frame decorator, defer to that wrapped object's method - if it has one. This allows for frame decorators that have - sub-classed FrameDecorator object, but also wrap other frame - decorators on the same frame to correctly execute. - - E.g - - If the result of frame filters running means we have one gdb.Frame - wrapped by multiple frame decorators, all sub-classed from - FrameDecorator, the resulting hierarchy will be: - - Decorator1 - -- (wraps) Decorator2 - -- (wraps) FrameDecorator - -- (wraps) gdb.Frame - - In this case we have two frame decorators, both of which are - sub-classed from FrameDecorator. If Decorator1 just overrides the - 'function' method, then all of the other methods are carried out - by the super-class FrameDecorator. But Decorator2 may have - overriden other methods, so FrameDecorator will look at the - 'base' parameter and defer to that class's methods. And so on, - down the chain.""" +class _FrameDecoratorBase(object): + """Base class of frame decorators.""" # 'base' can refer to a gdb.Frame or another frame decorator. In # the latter case, the child class will have called the super @@ -122,22 +96,6 @@ class FrameDecorator(object): frame = self.inferior_frame() return frame.pc() - def filename(self): - """Return the filename associated with this frame, detecting - and returning the appropriate library name is this is a shared - library.""" - - if hasattr(self._base, "filename"): - return self._base.filename() - - frame = self.inferior_frame() - sal = frame.find_sal() - if not sal.symtab or not sal.symtab.filename: - pc = frame.pc() - return gdb.solib_name(pc) - else: - return sal.symtab.filename - def frame_args(self): """Return an iterable of frame arguments for this frame, if any. The iterable object contains objects conforming with the @@ -198,6 +156,71 @@ class FrameDecorator(object): return self._base +class FrameDecorator(_FrameDecoratorBase): + """Basic implementation of a Frame Decorator""" + + """ This base frame decorator decorates a frame or another frame + decorator, and provides convenience methods. If this object is + wrapping a frame decorator, defer to that wrapped object's method + if it has one. This allows for frame decorators that have + sub-classed FrameDecorator object, but also wrap other frame + decorators on the same frame to correctly execute. + + E.g + + If the result of frame filters running means we have one gdb.Frame + wrapped by multiple frame decorators, all sub-classed from + FrameDecorator, the resulting hierarchy will be: + + Decorator1 + -- (wraps) Decorator2 + -- (wraps) FrameDecorator + -- (wraps) gdb.Frame + + In this case we have two frame decorators, both of which are + sub-classed from FrameDecorator. If Decorator1 just overrides the + 'function' method, then all of the other methods are carried out + by the super-class FrameDecorator. But Decorator2 may have + overriden other methods, so FrameDecorator will look at the + 'base' parameter and defer to that class's methods. And so on, + down the chain.""" + + def filename(self): + """Return the filename associated with this frame, detecting + and returning the appropriate library name is this is a shared + library.""" + + if hasattr(self._base, "filename"): + return self._base.filename() + + frame = self.inferior_frame() + sal = frame.find_sal() + if not sal.symtab or not sal.symtab.filename: + pc = frame.pc() + return gdb.solib_name(pc) + else: + return sal.symtab.filename + + +class DAPFrameDecorator(_FrameDecoratorBase): + """Like FrameDecorator, but has slightly different results + for the "filename" method.""" + + def filename(self): + """Return the filename associated with this frame, detecting + and returning the appropriate library name is this is a shared + library.""" + + if hasattr(self._base, "filename"): + return self._base.filename() + + frame = self.inferior_frame() + sal = frame.find_sal() + if sal.symtab is not None: + return sal.symtab.fullname() + return None + + class SymValueWrapper(object): """A container class conforming to the Symbol/Value interface which holds frame locals or frame arguments.""" diff --git a/gdb/python/lib/gdb/frames.py b/gdb/python/lib/gdb/frames.py index cff3ba07704..104ff4bb203 100644 --- a/gdb/python/lib/gdb/frames.py +++ b/gdb/python/lib/gdb/frames.py @@ -18,7 +18,7 @@ import gdb from gdb.FrameIterator import FrameIterator -from gdb.FrameDecorator import FrameDecorator +from gdb.FrameDecorator import FrameDecorator, DAPFrameDecorator import itertools import collections @@ -172,7 +172,11 @@ def _frame_iterator(frame, frame_low, frame_high, always): # Apply a basic frame decorator to all gdb.Frames. This unifies # the interface. - frame_iterator = map(FrameDecorator, frame_iterator) + if always: + decorator = DAPFrameDecorator + else: + decorator = FrameDecorator + frame_iterator = map(decorator, frame_iterator) for ff in sorted_list: frame_iterator = ff.filter(frame_iterator) @@ -214,7 +218,11 @@ def frame_iterator(frame, frame_low, frame_high): """Helper function that will execute the chain of frame filters. Each filter is executed in priority order. After the execution completes, slice the iterator to frame_low - frame_high range. An - iterator is always returned. + iterator is always returned. The iterator will always yield + frame decorator objects, but note that these decorators have + slightly different semantics from the ordinary ones: they will + always return a fully-qualified 'filename' (if possible) and will + never substitute the objfile name. Arguments: frame: The initial frame. -- 2.40.1