From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from eggs.gnu.org (eggs.gnu.org [IPv6:2001:470:142:3::10]) by sourceware.org (Postfix) with ESMTPS id 5DCC0385801F for ; Wed, 3 Nov 2021 16:31:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5DCC0385801F Received: from fencepost.gnu.org ([2001:470:142:3::e]:59200) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1miJAd-0006wj-Py for gdb@sourceware.org; Wed, 03 Nov 2021 12:31:27 -0400 Received: from ip5f5a8d68.dynamic.kabel-deutschland.de ([95.90.141.104]:55810 helo=[192.168.111.41]) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1miJAd-0007U9-H2 for gdb@sourceware.org; Wed, 03 Nov 2021 12:31:27 -0400 From: Simon Sobisch To: gdb@sourceware.org References: <60c53fa8bf160533a2eddf1da280eb50c7461a6a.camel@fit.cvut.cz> Subject: How to get the full source location of a frame via python Message-ID: Date: Wed, 3 Nov 2021 17:31:24 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <60c53fa8bf160533a2eddf1da280eb50c7461a6a.camel@fit.cvut.cz> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=1.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_BARRACUDACENTRAL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.4 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Nov 2021 16:31:29 -0000 With the Python API we can do nearly everything necessary related to frames and st = frame.find_sal().symtab if st: filename = st.filename provides the filename as noted in the debug info. If we now need to get the full filename as used in GDB (with source path and similar applied) the only version I've found so far involves GDB text parsing: # Get the full path for the source file old_frame = gdb.selected_frame() frame.select() info_source = gdb.execute("info source", False, True) pattern = re.compile(r"Located in (.*)\n") match = re.search(pattern, info_source) if match: self.current_full_path = match.group(1) else: self.current_full_path = filename_frame old_frame.select() Which seems not very robust as it parses text which may have a different format in other GDB versions and likely a different text when localized; additional it needs a regex which is not that fast. Questions: Is there a direct way to get the full source location for a frame? If not: any suggestions to improve the code (especially the reliability?) Also: if there isn't a way via GDBs python API please consider this as a feature request, maybe as gdb.Frame.resolve_filename() Simon