From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23807 invoked by alias); 17 Dec 2010 14:18:26 -0000 Received: (qmail 23799 invoked by uid 22791); 17 Dec 2010 14:18:25 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from ms9.webland.ch (HELO ms9smtp.webland.ch) (92.43.217.109) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 17 Dec 2010 14:18:20 +0000 Received: from macserver.private ([84.74.43.109]) by ms9smtp.webland.ch (Webland Mail Server v10.0) with ASMTP id ZAJ42816 for ; Fri, 17 Dec 2010 15:18:16 +0100 Received: from localhost (localhost [127.0.0.1]) by macserver.private (Postfix) with ESMTP id 7C7E4A64BED; Fri, 17 Dec 2010 15:18:14 +0100 (CET) Received: from macserver.private ([127.0.0.1]) by localhost (macserver.private [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id OmRajvWdEiW5; Fri, 17 Dec 2010 15:18:14 +0100 (CET) Received: from [192.168.1.86] (unknown [192.168.1.86]) by macserver.private (Postfix) with ESMTP id 094C0A64BE0 for ; Fri, 17 Dec 2010 15:18:13 +0100 (CET) Message-ID: <4D0B7125.2010203@indel.ch> Date: Fri, 17 Dec 2010 14:18:00 -0000 From: Raphael Zulliger User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101207 Lightning/1.0b2 Thunderbird/3.1.7 MIME-Version: 1.0 To: gdb-patches@sourceware.org Subject: proposal: substitute-path handles foreign dir separators Content-Type: multipart/mixed; boundary="------------000202090805040208080001" X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-12/txt/msg00340.txt.bz2 This is a multi-part message in MIME format. --------------000202090805040208080001 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 2336 Hi This is my first patch sent to this list. Please let me know if I'm doing something wrong. This is a not a bug fix, it's a feature: This patch extends 'substitute-path' to handle paths containing 'foreign' directory separators. Means e.g.: A powerpc-eabi-gdb running on Linux can handle powerpc-eabi-binaries built on Windows and vice versa. Several points need to be considered: 1. Most importantly: Do we want such a 'feature'? Personally, I think it makes sense to have such a feature. A prominent use case may occur when developing for an embedded system. Having platform independent IDEs like Eclipse together with the GNU toolchain (cygwin, mingw, *nix) makes it possible that some members of a development team work on e.g. Windows, while the rest works on e.g. Linux. "Working" in this case could mean that people compile their code and probably create libraries on their (preferred) OS. Later these libraries will be linked together to a binary which will end up on an embedded target that needs to be debugged. (Sure you can argue that this wouldn't happen if they'd use a buildmachine, but...). Debugging, again, may be done by a person using Linux or Windows. That's where this patch would become useful. To continue the discussion lets assume that we all want this feature. 2. I created this patch because I actually debug binaries on a Linux box which have been created on a Windows machine (GNU toolchain/Cygwin). Empirically, I've realized that 'substitute-path' doesn't work for this purpose. After having single-stepped GDB and modified its code slightly, I ended up with this patch. The point is that I figured it out empirically. It could the case that I justed missed an already existing solution. Please let me know if my patch is crap because there exists another way of handling my use case. 3. I didn't write any tests yet. I would write them if the patch would get accepted. If this would be the case, it would be nice if you could give me some hints where to start (which file, what kind of test, ...) 4. I didn't verify/test my code on any other system than Linux. I could test it on Windows (mingw) if you would accept the patch 5. I didn't yet fill out the 'copyright assignment' form (mentioned in the CONTRIBUTE file). I would do so if required. Raphael --------------000202090805040208080001 Content-Type: text/plain; name="substitute-path.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="substitute-path.diff" Content-length: 2267 *** /tmp/gdb-7.2/gdb/source.c 2010-12-17 14:12:11.618336763 +0100 --- gdb-7.2/gdb/source.c 2010-12-17 14:13:02.347583097 +0100 *************** substitute_path_rule_matches (const stru *** 882,888 **** /* Make sure that the region in the path that matches the substitution rule is immediately followed by a directory separator (or the end of string character). */ ! if (path[from_len] != '\0' && !IS_DIR_SEPARATOR (path[from_len])) return 0; return 1; --- 882,888 ---- /* Make sure that the region in the path that matches the substitution rule is immediately followed by a directory separator (or the end of string character). */ ! if (path[from_len] != '\0' && (!IS_UNIX_DIR_SEPARATOR (path[from_len]) && !IS_DOS_DIR_SEPARATOR (path[from_len]))) return 0; return 1; *************** find_and_open_source (const char *filena *** 1015,1021 **** } } ! if (IS_ABSOLUTE_PATH (filename)) { /* If filename is absolute path, try the source path substitution on it. */ --- 1015,1021 ---- } } ! if (IS_UNIX_ABSOLUTE_PATH (filename) || IS_DOS_ABSOLUTE_PATH(filename)) { /* If filename is absolute path, try the source path substitution on it. */ *************** find_and_open_source (const char *filena *** 1023,1028 **** --- 1023,1046 ---- if (rewritten_filename != NULL) { + /* Especially for embedded systems, it may be the case that a + binary has been built on Windows but the embedded system is now + being debugged on a Unix machine (and vice versa). In order to + make path substitution work on such 'mixed' path styles, we need + to convert foreign dir separators to native ones. */ + #ifdef HAVE_DOS_BASED_FILE_SYSTEM + const char from = '/'; + const char to = '\\'; + #else + const char from = '\\'; + const char to = '/'; + #endif + unsigned int i=0; + for( i=0; i