2001-09-20 04:02:59 +04:00
|
|
|
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
1999-11-04 09:06:13 +03:00
|
|
|
*
|
2001-09-20 04:02:59 +04:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
1999-11-04 09:06:13 +03:00
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
2001-09-20 04:02:59 +04:00
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1999-11-04 09:06:13 +03:00
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS
|
2002-03-19 07:30:17 +03:00
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
1999-11-04 09:06:13 +03:00
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
2001-09-20 04:02:59 +04:00
|
|
|
* The Original Code is Mozilla Communicator client code, released
|
|
|
|
* March 31, 1998.
|
1999-11-04 09:06:13 +03:00
|
|
|
*
|
2001-09-20 04:02:59 +04:00
|
|
|
* The Initial Developer of the Original Code is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-04 09:06:13 +03:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
2001-09-20 04:02:59 +04:00
|
|
|
* Patrick C. Beard <beard@netscape.com>
|
2001-09-20 02:39:41 +04:00
|
|
|
*
|
2001-09-20 04:02:59 +04:00
|
|
|
* Alternatively, the contents of this file may be used under the
|
|
|
|
* terms of the GNU Public License (the "GPL"), in which case the
|
|
|
|
* provisions of the GPL are applicable instead of those above.
|
|
|
|
* If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of the GPL and not to allow others to use your
|
|
|
|
* version of this file under the NPL, indicate your decision by
|
|
|
|
* deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this
|
|
|
|
* file under either the NPL or the GPL.
|
|
|
|
*/
|
1999-11-04 09:06:13 +03:00
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
public class FileLocator {
|
|
|
|
static boolean USE_BLAME = false;
|
1999-11-06 06:23:49 +03:00
|
|
|
static boolean ASSIGN_BLAME = false;
|
1999-11-04 09:06:13 +03:00
|
|
|
|
2000-04-03 19:54:59 +04:00
|
|
|
static final String MOZILLA_BASE = "/mozilla/";
|
1999-11-04 09:06:13 +03:00
|
|
|
static final String LXR_BASE = "http://lxr.mozilla.org/seamonkey/source/";
|
2000-01-30 22:05:36 +03:00
|
|
|
static final String BONSAI_BASE = "http://bonsai.mozilla.org/cvsblame.cgi?file=";
|
1999-11-04 09:06:13 +03:00
|
|
|
|
2000-04-03 19:54:59 +04:00
|
|
|
static final String NS_BASE = "/ns/";
|
|
|
|
static final String NS_BONSAI_URL = "http://warp.mcom.com/webtools/bonsai/cvsblame.cgi?root=/m/src&file=";
|
|
|
|
|
1999-11-04 09:06:13 +03:00
|
|
|
static final Hashtable fileTables = new Hashtable();
|
|
|
|
static final RevisionTable revisionTable = new RevisionTable();
|
|
|
|
static final BlameTable blameTable = new BlameTable();
|
2000-08-31 05:08:16 +04:00
|
|
|
static final Hashtable addr2LineTable = new Hashtable();
|
1999-11-04 09:06:13 +03:00
|
|
|
|
2000-04-10 21:40:08 +04:00
|
|
|
public static String getFileLocation(byte[] line) throws IOException {
|
|
|
|
return getFileLocation(new String(line));
|
|
|
|
}
|
|
|
|
|
1999-11-04 09:06:13 +03:00
|
|
|
public static String getFileLocation(String line) throws IOException {
|
2000-04-10 21:40:08 +04:00
|
|
|
// start from the LAST occurence of '[', as C++ symbols can include it.
|
|
|
|
int leftBracket = line.lastIndexOf('[');
|
1999-11-04 09:06:13 +03:00
|
|
|
if (leftBracket == -1)
|
|
|
|
return line;
|
|
|
|
int rightBracket = line.indexOf(']', leftBracket + 1);
|
|
|
|
if (rightBracket == -1)
|
|
|
|
return line;
|
2000-08-18 07:16:29 +04:00
|
|
|
|
|
|
|
// generalize for Linux & Mac versions of the Leak detector.
|
|
|
|
String fullPath;
|
|
|
|
int lineNumber, lineAnchor;
|
2000-08-21 00:04:44 +04:00
|
|
|
int comma = line.indexOf(',', leftBracket + 1);
|
|
|
|
if (comma != -1) {
|
2000-08-18 07:16:29 +04:00
|
|
|
// Mac format: unmangled_symbol[mac_path,byte_offset]
|
|
|
|
String macPath = line.substring(leftBracket + 1, comma);
|
|
|
|
fullPath = "/" + macPath.replace(':', '/');
|
1999-11-04 09:06:13 +03:00
|
|
|
|
2000-08-18 07:16:29 +04:00
|
|
|
// compute the line number in the file.
|
|
|
|
int offset = 0;
|
|
|
|
try {
|
|
|
|
offset = Integer.parseInt(line.substring(comma + 1, rightBracket));
|
|
|
|
} catch (NumberFormatException nfe) {
|
|
|
|
return line;
|
|
|
|
} catch (StringIndexOutOfBoundsException sobe) {
|
|
|
|
System.err.println("### Error processing line: " + line);
|
|
|
|
System.err.println("### comma = " + comma + ", rightBracket = " + rightBracket);
|
|
|
|
System.err.flush();
|
|
|
|
return line;
|
|
|
|
}
|
2000-04-10 21:40:08 +04:00
|
|
|
|
2000-08-18 07:16:29 +04:00
|
|
|
FileTable table = (FileTable) fileTables.get(fullPath);
|
|
|
|
if (table == null) {
|
|
|
|
table = new FileTable(fullPath);
|
|
|
|
fileTables.put(fullPath, table);
|
|
|
|
}
|
|
|
|
lineNumber = 1 + table.getLine(offset);
|
|
|
|
lineAnchor = lineNumber;
|
2000-08-21 00:04:44 +04:00
|
|
|
} else {
|
2000-08-31 05:08:16 +04:00
|
|
|
int space = line.indexOf(' ', leftBracket + 1);
|
|
|
|
if (space != -1) {
|
|
|
|
// Raw Linux format: mangled_symbol[library +address]
|
|
|
|
String library = line.substring(leftBracket + 1, space);
|
|
|
|
String address = line.substring(space + 1, rightBracket);
|
|
|
|
Addr2Line addr2line = (Addr2Line) addr2LineTable.get(library);
|
|
|
|
if (addr2line == null) {
|
|
|
|
System.out.println("new Addr2Line["+library+"]");
|
|
|
|
addr2line = new Addr2Line(library);
|
|
|
|
addr2LineTable.put(library, addr2line);
|
|
|
|
}
|
|
|
|
line = addr2line.getLine(address);
|
|
|
|
return getFileLocation(line);
|
|
|
|
} else {
|
|
|
|
// Linux format: unmangled_symbol[unix_path:line_number]
|
|
|
|
int colon = line.indexOf(':', leftBracket + 1);
|
|
|
|
fullPath = line.substring(leftBracket + 1, colon);
|
|
|
|
try {
|
|
|
|
lineNumber = Integer.parseInt(line.substring(colon + 1, rightBracket));
|
|
|
|
} catch (NumberFormatException nfe) {
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
lineAnchor = lineNumber;
|
2000-08-21 00:04:44 +04:00
|
|
|
}
|
2000-08-18 07:16:29 +04:00
|
|
|
}
|
2000-08-21 00:04:44 +04:00
|
|
|
|
1999-11-04 09:06:13 +03:00
|
|
|
// compute the URL of the file.
|
|
|
|
int mozillaIndex = fullPath.indexOf(MOZILLA_BASE);
|
|
|
|
String locationURL = null, blameInfo = "";
|
|
|
|
if (mozillaIndex > -1) {
|
|
|
|
// if using blame, hilite the line number of the call, and include the revision.
|
2000-04-03 19:54:59 +04:00
|
|
|
String mozillaPath = fullPath.substring(mozillaIndex + 1);
|
1999-11-06 06:23:49 +03:00
|
|
|
String revision = revisionTable.getRevision(fullPath);
|
2000-02-29 01:44:21 +03:00
|
|
|
String bonsaiPath = mozillaPath + (revision.length() > 0 ? "&rev=" + revision : "");
|
1999-11-04 09:06:13 +03:00
|
|
|
if (USE_BLAME) {
|
1999-11-06 06:23:49 +03:00
|
|
|
locationURL = BONSAI_BASE + bonsaiPath + "&mark=" + lineNumber;
|
1999-11-04 09:06:13 +03:00
|
|
|
if (lineAnchor > 10)
|
|
|
|
lineAnchor -= 10;
|
|
|
|
} else {
|
|
|
|
locationURL = LXR_BASE + mozillaPath.substring(MOZILLA_BASE.length());
|
|
|
|
}
|
1999-11-06 06:23:49 +03:00
|
|
|
if (ASSIGN_BLAME)
|
|
|
|
blameInfo = " (" + blameTable.getBlame(bonsaiPath, lineNumber) + ")";
|
1999-11-04 09:06:13 +03:00
|
|
|
} else {
|
2000-04-03 19:54:59 +04:00
|
|
|
int nsIndex = fullPath.indexOf(NS_BASE);
|
|
|
|
if (nsIndex > -1 && USE_BLAME) {
|
|
|
|
// if using blame, hilite the line number of the call, and include the revision.
|
|
|
|
String nsPath = fullPath.substring(nsIndex + 1);
|
|
|
|
String revision = revisionTable.getRevision(fullPath);
|
|
|
|
String bonsaiPath = nsPath + (revision.length() > 0 ? "&rev=" + revision : "");
|
|
|
|
locationURL = NS_BONSAI_URL + bonsaiPath + "&mark=" + lineNumber;
|
|
|
|
if (lineAnchor > 10)
|
|
|
|
lineAnchor -= 10;
|
|
|
|
if (ASSIGN_BLAME)
|
|
|
|
blameInfo = " (" + blameTable.getBlame(bonsaiPath, lineNumber) + ")";
|
|
|
|
} else {
|
|
|
|
locationURL = "file://" + fullPath;
|
|
|
|
}
|
1999-11-04 09:06:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return "<A HREF=\"" + locationURL + "#" + lineAnchor + "\"TARGET=\"SOURCE\">" + line.substring(0, leftBracket) + "</A>" + blameInfo;
|
|
|
|
}
|
|
|
|
}
|
2000-04-03 19:54:59 +04:00
|
|
|
|